Fixes #7946 Fixed a bug when the form attribute was not propagated to the hidden input of the checkbox

This commit is contained in:
Nikolay Oleynikov
2017-02-27 13:47:37 +03:00
committed by Alexander Makarov
parent 953a0bba2b
commit f47b6c7683
3 changed files with 14 additions and 1 deletions

View File

@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.12 under development 2.0.12 under development
-------------------------- --------------------------
- Bug #7946 Fixed a bug when the `form` attribute was not propagated to the hidden input of the checkbox (Kolyunya)
- Bug #13087: Fixed getting active validators for safe attribute (developeruz) - Bug #13087: Fixed getting active validators for safe attribute (developeruz)
- Bug #13571: Fix `yii\db\mssql\QueryBuilder::checkIntegrity` for all tables (boboldehampsink) - Bug #13571: Fix `yii\db\mssql\QueryBuilder::checkIntegrity` for all tables (boboldehampsink)
- Bug #11230: Include `defaultRoles` in `yii\rbac\DbManager->getRolesByUser()` results (developeruz) - Bug #11230: Include `defaultRoles` in `yii\rbac\DbManager->getRolesByUser()` results (developeruz)

View File

@ -60,6 +60,7 @@ class BaseHtml
'href', 'href',
'src', 'src',
'srcset', 'srcset',
'form',
'action', 'action',
'method', 'method',
@ -742,7 +743,11 @@ class BaseHtml
$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
$hidden = static::hiddenInput($name, $options['uncheck']); $hiddenOptions = [];
if (isset($options['form'])) {
$hiddenOptions['form'] = $options['form'];
}
$hidden = static::hiddenInput($name, $options['uncheck'], $hiddenOptions);
unset($options['uncheck']); unset($options['uncheck']);
} else { } else {
$hidden = ''; $hidden = '';

View File

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