Skip to content

Commit

Permalink
Fixes yiisoft#11960: Fixed checked option ignore in `yii\helpers\Ba…
Browse files Browse the repository at this point in the history
…seHtml::checkbox()`
  • Loading branch information
misantron authored and samdark committed Oct 7, 2018
1 parent 0ad5afd commit af3b8b2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Yii Framework 2 Change Log
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 #16490: Fix schema on rbac init (marcelodeandrade)
- Bug #16748: Fixed params when normalize data (marcelodeandrade)
Expand Down
5 changes: 4 additions & 1 deletion framework/helpers/BaseHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,10 @@ public static function checkbox($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';
if (isset($options['uncheck'])) {
// add a hidden field so that if the checkbox is not selected, it still submits a value
Expand Down
7 changes: 7 additions & 0 deletions tests/framework/helpers/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,13 @@ public function testCheckbox()
'value' => 2,
'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()
Expand Down

0 comments on commit af3b8b2

Please sign in to comment.