Fixes #11960: Fixed checked option ignore in yii\helpers\BaseHtml::checkbox()

This commit is contained in:
Alexandr Ivanov
2018-10-07 16:29:08 +03:00
committed by Alexander Makarov
parent 0ad5afd387
commit af3b8b2f23
3 changed files with 12 additions and 1 deletions

View File

@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.16 under development 2.0.16 under development
------------------------ ------------------------
- Bug #11960: Fixed `checked` option ignore in `yii\helpers\BaseHtml::checkbox()` (misantron)
- Bug #14759: Fixed `yii\web\JsonResponseFormatter` output for `null` data (misantron) - Bug #14759: Fixed `yii\web\JsonResponseFormatter` output for `null` data (misantron)
- Bug #16490: Fix schema on rbac init (marcelodeandrade) - Bug #16490: Fix schema on rbac init (marcelodeandrade)
- Bug #16748: Fixed params when normalize data (marcelodeandrade) - Bug #16748: Fixed params when normalize data (marcelodeandrade)

View File

@ -751,7 +751,10 @@ class BaseHtml
*/ */
protected static function booleanInput($type, $name, $checked = false, $options = []) protected static function booleanInput($type, $name, $checked = false, $options = [])
{ {
$options['checked'] = (bool) $checked; // 'checked' option has priority over $checked argument
if (!isset($options['checked'])) {
$options['checked'] = (bool) $checked;
}
$value = array_key_exists('value', $options) ? $options['value'] : '1'; $value = array_key_exists('value', $options) ? $options['value'] : '1';
if (isset($options['uncheck'])) { if (isset($options['uncheck'])) {
// add a hidden field so that if the checkbox is not selected, it still submits a value // add a hidden field so that if the checkbox is not selected, it still submits a value

View File

@ -477,6 +477,13 @@ class HtmlTest extends TestCase
'value' => 2, 'value' => 2,
'form' => 'test-form', 'form' => 'test-form',
])); ]));
$this->assertEquals('<input type="hidden" name="test" value="0"><label><input type="checkbox" class="a" name="test" value="2" checked> ccc</label>', Html::checkbox('test', false, [
'class' => 'a',
'uncheck' => '0',
'label' => 'ccc',
'value' => 2,
'checked' => true,
]));
} }
public function testDropDownList() public function testDropDownList()