Skip to content
Snippets Groups Projects
Commit fe766fd1 authored by Andreas Gohr's avatar Andreas Gohr Committed by GitHub
Browse files

Merge pull request #1801 from splitbrain/fixOptGroupNumericArrays

Allow form dropdown options as arrays with numeric keys
parents 09679584 ddb6c308
No related branches found
No related tags found
No related merge requests found
......@@ -58,7 +58,10 @@ class form_dropdownelement_test extends DokuWikiTest {
'data-foo' => 'bar'
)
),
'second'
'second',
'3' => array(
'label' => 'the label of the complex third option',
)
);
$form->addDropdown('foo', $options, 'label text');
......@@ -70,7 +73,7 @@ class form_dropdownelement_test extends DokuWikiTest {
$this->assertTrue($select->length == 1);
$options = $pq->find('option');
$this->assertTrue($options->length == 2);
$this->assertEquals(3, $options->length);
$option = $pq->find('option#theID');
$this->assertEquals(1, $option->length);
......
......@@ -50,13 +50,13 @@ class OptGroup extends Element {
if(!is_array($options)) throw new \InvalidArgumentException('Options have to be an array');
$this->options = array();
foreach($options as $key => $val) {
if(is_int($key)) {
$this->options[$val] = array('label' => (string) $val);
} elseif (!is_array($val)) {
$this->options[$key] = array('label' => (string) $val);
} else {
if (is_array($val)) {
if (!key_exists('label', $val)) throw new \InvalidArgumentException('If option is given as array, it has to have a "label"-key!');
$this->options[$key] = $val;
} elseif(is_int($key)) {
$this->options[$val] = array('label' => (string) $val);
} else {
$this->options[$key] = array('label' => (string) $val);
}
}
return $this;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment