mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +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)
|
- 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)
|
- 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 #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
|
2.0.8 April 28, 2016
|
||||||
--------------------
|
--------------------
|
||||||
|
@ -1702,9 +1702,11 @@ class BaseHtml
|
|||||||
} else {
|
} else {
|
||||||
$attrs = isset($options[$key]) ? $options[$key] : [];
|
$attrs = isset($options[$key]) ? $options[$key] : [];
|
||||||
$attrs['value'] = (string) $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) && !strcmp($key, $selection)
|
||||||
|| ArrayHelper::isTraversable($selection) && ArrayHelper::isIn($key, $selection));
|
|| ArrayHelper::isTraversable($selection) && ArrayHelper::isIn($key, $selection));
|
||||||
|
}
|
||||||
$text = $encode ? static::encode($value) : $value;
|
$text = $encode ? static::encode($value) : $value;
|
||||||
if ($encodeSpaces) {
|
if ($encodeSpaces) {
|
||||||
$text = str_replace(' ', ' ', $text);
|
$text = str_replace(' ', ' ', $text);
|
||||||
|
@ -280,6 +280,18 @@ EOD;
|
|||||||
</select>
|
</select>
|
||||||
EOD;
|
EOD;
|
||||||
$this->assertEqualsWithoutLE($expected, Html::dropDownList('test', 'value2', $this->getDataItems()));
|
$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()
|
public function testListBox()
|
||||||
|
Reference in New Issue
Block a user