From af3b8b2f23a54b7d20617b7198e5c95aaac92cf8 Mon Sep 17 00:00:00 2001 From: Alexandr Ivanov Date: Sun, 7 Oct 2018 16:29:08 +0300 Subject: [PATCH] Fixes #11960: Fixed `checked` option ignore in `yii\helpers\BaseHtml::checkbox()` --- framework/CHANGELOG.md | 1 + framework/helpers/BaseHtml.php | 5 ++++- tests/framework/helpers/HtmlTest.php | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 55a26d2991..ecd2d50c5d 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -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) diff --git a/framework/helpers/BaseHtml.php b/framework/helpers/BaseHtml.php index ac9db2f020..8b6eb378fd 100644 --- a/framework/helpers/BaseHtml.php +++ b/framework/helpers/BaseHtml.php @@ -751,7 +751,10 @@ class BaseHtml */ 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 diff --git a/tests/framework/helpers/HtmlTest.php b/tests/framework/helpers/HtmlTest.php index 88dda3ad8f..78f6bc7098 100644 --- a/tests/framework/helpers/HtmlTest.php +++ b/tests/framework/helpers/HtmlTest.php @@ -477,6 +477,13 @@ class HtmlTest extends TestCase 'value' => 2, 'form' => 'test-form', ])); + $this->assertEquals('', Html::checkbox('test', false, [ + 'class' => 'a', + 'uncheck' => '0', + 'label' => 'ccc', + 'value' => 2, + 'checked' => true, + ])); } public function testDropDownList()