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

Merge pull request #2157 from splitbrain/fixDoubleSelected

fix: prevent two selected options, b/c apparently 'String' == 0  :face_palm:
parents 07ca0ccf 389e1856
No related branches found
No related tags found
No related merge requests found
......@@ -129,6 +129,21 @@ class form_dropdownelement_test extends DokuWikiTest {
$this->assertEquals('label of third option', $selected->text());
}
/**
* Prevent double select that might occur because `'Auto' == 0` is true
*/
public function test_doubleselect() {
$form = new Form\Form();
$form->addDropdown('foo', ['Auto', 0, 1]);
$html = $form->toHTML();
$pq = phpQuery::newDocumentXHTML($html);
$selected = $pq->find('option[selected=selected]');
$this->assertEquals(1, $selected->length);
$this->assertEquals('Auto', $selected->text());
}
/**
* Ensure that there is always only a single one selected option
*/
......
......@@ -88,7 +88,7 @@ class OptGroup extends Element {
protected function renderOptions() {
$html = '';
foreach($this->options as $key => $val) {
$selected = ($key == $this->value) ? ' selected="selected"' : '';
$selected = ((string)$key === (string)$this->value) ? ' selected="selected"' : '';
$attrs = '';
if (!empty($val['attrs']) && is_array($val['attrs'])) {
$attrs = buildAttributes($val['attrs']);
......
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