mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
Fixes #11865: Fixed setting selected
for dropdown list using options
This commit is contained in:
@ -47,6 +47,7 @@ Yii Framework 2 Change Log
|
||||
- Bug #10681: Fixed active form `beforeValidate` wasn't triggered in some cases (lynicidn)
|
||||
- Enh #11857: `yii\filters\AccessRule::$verbs` could not be configured with any case of request method names (DrDeath72, samdark)
|
||||
- Bug #11863: Fixed usage of `mb_substr` with PHP < 5.4.8 where length of NULL was treated the same as 0 (samdark)
|
||||
- Bug #11865: Fixed setting `selected` for dropdown list using options (samdark)
|
||||
|
||||
2.0.8 April 28, 2016
|
||||
--------------------
|
||||
|
@ -1702,9 +1702,11 @@ class BaseHtml
|
||||
} else {
|
||||
$attrs = isset($options[$key]) ? $options[$key] : [];
|
||||
$attrs['value'] = (string) $key;
|
||||
$attrs['selected'] = $selection !== null &&
|
||||
if (!array_key_exists('selected', $attrs)) {
|
||||
$attrs['selected'] = $selection !== null &&
|
||||
(!ArrayHelper::isTraversable($selection) && !strcmp($key, $selection)
|
||||
|| ArrayHelper::isTraversable($selection) && ArrayHelper::isIn($key, $selection));
|
||||
}
|
||||
$text = $encode ? static::encode($value) : $value;
|
||||
if ($encodeSpaces) {
|
||||
$text = str_replace(' ', ' ', $text);
|
||||
|
@ -280,6 +280,18 @@ EOD;
|
||||
</select>
|
||||
EOD;
|
||||
$this->assertEqualsWithoutLE($expected, Html::dropDownList('test', 'value2', $this->getDataItems()));
|
||||
|
||||
$expected = <<<EOD
|
||||
<select name="test">
|
||||
<option value="value1">text1</option>
|
||||
<option value="value2" selected>text2</option>
|
||||
</select>
|
||||
EOD;
|
||||
$this->assertEqualsWithoutLE($expected, Html::dropDownList('test', null, $this->getDataItems(), [
|
||||
'options' => [
|
||||
'value2' => ['selected' => true]
|
||||
],
|
||||
]));
|
||||
}
|
||||
|
||||
public function testListBox()
|
||||
|
Reference in New Issue
Block a user