mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-16 07:11:19 +08:00
19324 dropdownlist selection for boolean attributes (#19331)
* Fix #19324 by allowing for direct comparison * Invert meaning of strict * Remove WinterSilence from authors list * Fix improper implementation of strict checks * Add test for renderSelectOptions * Partially revert 'Fix improper implementation of strict checks' * Add additional tests for strict * Revert 'Fix improper implementation of strict checks' * Add failing test for demonstration * Comment out demonstration test * Update framework/CHANGELOG.md Co-authored-by: Bizley <pawel@positive.codes> Co-authored-by: Bizley <pawel@positive.codes>
This commit is contained in:
@ -16,6 +16,7 @@ Yii Framework 2 Change Log
|
|||||||
- Enh #19304: Add filtering validator `yii\validators\TrimValidator` (WinterSilence)
|
- Enh #19304: Add filtering validator `yii\validators\TrimValidator` (WinterSilence)
|
||||||
- Enh #19309: Optimize `yii\base\Model::attributes()` (WinterSilence)
|
- Enh #19309: Optimize `yii\base\Model::attributes()` (WinterSilence)
|
||||||
- Bug #19322: Revert force setting value to empty string in case it's `null` in `yii\validators\FilterValidator::validateAttribute()` (bizley)
|
- Bug #19322: Revert force setting value to empty string in case it's `null` in `yii\validators\FilterValidator::validateAttribute()` (bizley)
|
||||||
|
- Bug #19324: Fix `yii\helpers\BaseHtml::renderSelectOptions()` giving wrong selection for boolean attributes (adnandautovic)
|
||||||
- Bug #19329: Fix `yii\web\GroupUrlRule` to properly normalize prefix (bizley)
|
- Bug #19329: Fix `yii\web\GroupUrlRule` to properly normalize prefix (bizley)
|
||||||
- Bug #19328: Passing null to parameter #1 ($string) of type string is deprecated in `yii\db\oci\Schema` (Arkeins)
|
- Bug #19328: Passing null to parameter #1 ($string) of type string is deprecated in `yii\db\oci\Schema` (Arkeins)
|
||||||
- Bug #19237: Fix OCI PHP 8.1 passing `null` to trim() (longthanhtran)
|
- Bug #19237: Fix OCI PHP 8.1 passing `null` to trim() (longthanhtran)
|
||||||
|
@ -1914,7 +1914,7 @@ class BaseHtml
|
|||||||
$attrs['value'] = (string) $key;
|
$attrs['value'] = (string) $key;
|
||||||
if (!array_key_exists('selected', $attrs)) {
|
if (!array_key_exists('selected', $attrs)) {
|
||||||
$attrs['selected'] = $selection !== null &&
|
$attrs['selected'] = $selection !== null &&
|
||||||
(!ArrayHelper::isTraversable($selection) && !strcmp($key, $selection)
|
(!ArrayHelper::isTraversable($selection) && ($strict ? !strcmp($key, $selection) : $selection == $key)
|
||||||
|| ArrayHelper::isTraversable($selection) && ArrayHelper::isIn((string)$key, $selection, $strict));
|
|| ArrayHelper::isTraversable($selection) && ArrayHelper::isIn((string)$key, $selection, $strict));
|
||||||
}
|
}
|
||||||
$text = $encode ? static::encode($value) : $value;
|
$text = $encode ? static::encode($value) : $value;
|
||||||
|
@ -775,6 +775,14 @@ EOD;
|
|||||||
<label><input type="checkbox" name="test[]" value="1.10"> 1.10</label></div>
|
<label><input type="checkbox" name="test[]" value="1.10"> 1.10</label></div>
|
||||||
EOD;
|
EOD;
|
||||||
$this->assertEqualsWithoutLE($expected, Html::checkboxList('test', ['1.1'], ['1' => '1', '1.1' => '1.1', '1.10' => '1.10'], ['strict' => true]));
|
$this->assertEqualsWithoutLE($expected, Html::checkboxList('test', ['1.1'], ['1' => '1', '1.1' => '1.1', '1.10' => '1.10'], ['strict' => true]));
|
||||||
|
$this->assertEqualsWithoutLE($expected, Html::checkboxList('test', [1.1], ['1' => '1', '1.1' => '1.1', '1.10' => '1.10'], ['strict' => true]));
|
||||||
|
|
||||||
|
$expected = <<<'EOD'
|
||||||
|
<div><label><input type="checkbox" name="test[]" value="1"> 1</label>
|
||||||
|
<label><input type="checkbox" name="test[]" value="1.1" checked> 1.1</label>
|
||||||
|
<label><input type="checkbox" name="test[]" value="1.10" checked> 1.10</label></div>
|
||||||
|
EOD;
|
||||||
|
$this->assertEqualsWithoutLE($expected, Html::checkboxList('test', [1.1], ['1' => '1', '1.1' => '1.1', '1.10' => '1.10']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRadioListWithArrayExpression()
|
public function testRadioListWithArrayExpression()
|
||||||
@ -923,6 +931,14 @@ EOD;
|
|||||||
<label><input type="radio" name="test" value="1.10"> 1.10</label></div>
|
<label><input type="radio" name="test" value="1.10"> 1.10</label></div>
|
||||||
EOD;
|
EOD;
|
||||||
$this->assertEqualsWithoutLE($expected, Html::radioList('test', ['1.1'], ['1' => '1', '1.1' => '1.1', '1.10' => '1.10'], ['strict' => true]));
|
$this->assertEqualsWithoutLE($expected, Html::radioList('test', ['1.1'], ['1' => '1', '1.1' => '1.1', '1.10' => '1.10'], ['strict' => true]));
|
||||||
|
$this->assertEqualsWithoutLE($expected, Html::radioList('test', [1.1], ['1' => '1', '1.1' => '1.1', '1.10' => '1.10'], ['strict' => true]));
|
||||||
|
|
||||||
|
$expected = <<<'EOD'
|
||||||
|
<div><label><input type="radio" name="test" value="1"> 1</label>
|
||||||
|
<label><input type="radio" name="test" value="1.1" checked> 1.1</label>
|
||||||
|
<label><input type="radio" name="test" value="1.10" checked> 1.10</label></div>
|
||||||
|
EOD;
|
||||||
|
$this->assertEqualsWithoutLE($expected, Html::radioList('test', ['1.1'], ['1' => '1', '1.1' => '1.1', '1.10' => '1.10']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUl()
|
public function testUl()
|
||||||
@ -1069,6 +1085,15 @@ EOD;
|
|||||||
$data = ['1' => '1', '1.1' => '1.1', '1.10' => '1.10'];
|
$data = ['1' => '1', '1.1' => '1.1', '1.10' => '1.10'];
|
||||||
$attributes = ['strict' => true];
|
$attributes = ['strict' => true];
|
||||||
$this->assertEqualsWithoutLE($expected, Html::renderSelectOptions(['1.1'], $data, $attributes));
|
$this->assertEqualsWithoutLE($expected, Html::renderSelectOptions(['1.1'], $data, $attributes));
|
||||||
|
$attributes = ['strict' => true];
|
||||||
|
$this->assertEqualsWithoutLE($expected, Html::renderSelectOptions([1.1], $data, $attributes));
|
||||||
|
|
||||||
|
$expected = <<<'EOD'
|
||||||
|
<option value="1">1</option>
|
||||||
|
<option value="1.1" selected>1.1</option>
|
||||||
|
<option value="1.10" selected>1.10</option>
|
||||||
|
EOD;
|
||||||
|
$this->assertEqualsWithoutLE($expected, Html::renderSelectOptions([1.1], $data));
|
||||||
|
|
||||||
$expected = <<<'EOD'
|
$expected = <<<'EOD'
|
||||||
<option value="1">1</option>
|
<option value="1">1</option>
|
||||||
@ -1080,6 +1105,27 @@ EOD;
|
|||||||
$data = ['1' => '1', '1.1' => '1.1', 'group' => ['1.10' => '1.10']];
|
$data = ['1' => '1', '1.1' => '1.1', 'group' => ['1.10' => '1.10']];
|
||||||
$attributes = ['strict' => true];
|
$attributes = ['strict' => true];
|
||||||
$this->assertEqualsWithoutLE($expected, Html::renderSelectOptions(['1.10'], $data, $attributes));
|
$this->assertEqualsWithoutLE($expected, Html::renderSelectOptions(['1.10'], $data, $attributes));
|
||||||
|
|
||||||
|
$expected = <<<'EOD'
|
||||||
|
<option value="">Please select</option>
|
||||||
|
<option value="1">Yes</option>
|
||||||
|
<option value="0" selected>No</option>
|
||||||
|
EOD;
|
||||||
|
$data = [true => 'Yes', false => 'No'];
|
||||||
|
$attributes = ['prompt' => 'Please select'];
|
||||||
|
$this->assertEqualsWithoutLE($expected, Html::renderSelectOptions(false, $data, $attributes));
|
||||||
|
//$attributes = ['prompt' => 'Please select'];
|
||||||
|
//$this->assertEqualsWithoutLE($expected, Html::renderSelectOptions([false], $data, $attributes));
|
||||||
|
|
||||||
|
$expected = <<<'EOD'
|
||||||
|
<option value="">Please select</option>
|
||||||
|
<option value="1">Yes</option>
|
||||||
|
<option value="0">No</option>
|
||||||
|
EOD;
|
||||||
|
$attributes = ['prompt' => 'Please select', 'strict' => true];
|
||||||
|
$this->assertEqualsWithoutLE($expected, Html::renderSelectOptions(false, $data, $attributes));
|
||||||
|
$attributes = ['prompt' => 'Please select', 'strict' => true];
|
||||||
|
$this->assertEqualsWithoutLE($expected, Html::renderSelectOptions([false], $data, $attributes));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRenderTagAttributes()
|
public function testRenderTagAttributes()
|
||||||
|
Reference in New Issue
Block a user