[5.5] Validation in select field for boolean value of selected option (#490)
* [5.5] Validation in select field for boolean value of selected option * Adjustment
This commit is contained in:
1 parent
215f20b8c2
commit
b79edc7acf
2 files changed
+10
-2
No files matched your search
+4
-2
@@ -572,7 +572,7 @@ class FormBuilder
|
|||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $list
|
* @param array $list
|
||||||
* @param string $selected
|
* @param string|bool $selected
|
||||||
* @param array $selectAttributes
|
* @param array $selectAttributes
|
||||||
* @param array $optionsAttributes
|
* @param array $optionsAttributes
|
||||||
* @param array $optgroupsAttributes
|
* @param array $optgroupsAttributes
|
||||||
@@ -784,7 +784,9 @@ class FormBuilder
|
|||||||
} elseif ($selected instanceof Collection) {
|
} elseif ($selected instanceof Collection) {
|
||||||
return $selected->contains($value) ? 'selected' : null;
|
return $selected->contains($value) ? 'selected' : null;
|
||||||
}
|
}
|
||||||
|
if (is_int($value) && is_bool($selected)) {
|
||||||
|
return (bool)$value === $selected;
|
||||||
|
}
|
||||||
return ((string) $value === (string) $selected) ? 'selected' : null;
|
return ((string) $value === (string) $selected) ? 'selected' : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -464,6 +464,12 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
|
|||||||
'<select name="countries"><option value="1" selected="selected">L</option><option value="2">M</option></select>',
|
'<select name="countries"><option value="1" selected="selected">L</option><option value="2">M</option></select>',
|
||||||
$result
|
$result
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$select = $this->formBuilder->select('avc', [1 => 'Yes', 0 => 'No'], true, ['placeholder' => 'Select']);
|
||||||
|
$this->assertEquals(
|
||||||
|
'<select name="avc"><option value="">Select</option><option value="1" selected>Yes</option><option value="0" >No</option></select>',
|
||||||
|
$select
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSelectCollection()
|
public function testSelectCollection()
|
||||||
|
|||||||
Reference in new issue
Block a user