From b8c07f6839ef5facf67ff1482e3189abf1145978 Mon Sep 17 00:00:00 2001 From: Vladimir Shevchenko Date: Mon, 8 Aug 2016 13:26:38 +0300 Subject: [PATCH] Fixes #12009: Do not render "for" field label attribute for active form RadioList and CheckboxList --- framework/CHANGELOG.md | 1 + framework/widgets/ActiveField.php | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 67a2b184bc..7d1cdf0d50 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -5,6 +5,7 @@ Yii Framework 2 Change Log ------------------------ - Enh #12073: Added the ability to suppress the generation of input hint when it is specified through `Model::attributeHints()` (PowerGamer1) +- Bug #12009: Do not render "for" field label attribute for active form RadioList and CheckboxList (shevchik87, samdark) - Bug #12068: Added missing 'LEVEL_PROFILE' for the syslog target (Mak-Di) - Bug #11461: Fixed migration tool error when create migrate with comma in defaultValue (pana1990, s-o-f) - Bug #11912: Fixed PostgreSQL Schema to support negative default values for integer/float/decimal columns (nsknewbie) diff --git a/framework/widgets/ActiveField.php b/framework/widgets/ActiveField.php index 21b0f029e7..d61e228f44 100644 --- a/framework/widgets/ActiveField.php +++ b/framework/widgets/ActiveField.php @@ -152,6 +152,11 @@ class ActiveField extends Component */ private $_inputId; + /** + * @var bool if "for" field label attribute should be skipped. + */ + private $_skipLabelFor = false; + /** * PHP magic method that returns the string representation of this object. @@ -269,6 +274,11 @@ class ActiveField extends Component if ($label !== null) { $options['label'] = $label; } + + if ($this->_skipLabelFor) { + $options['for'] = null; + } + $this->parts['{label}'] = Html::activeLabel($this->model, $this->attribute, $options); return $this; @@ -631,6 +641,7 @@ class ActiveField extends Component public function checkboxList($items, $options = []) { $this->adjustLabelFor($options); + $this->_skipLabelFor = true; $this->parts['{input}'] = Html::activeCheckboxList($this->model, $this->attribute, $items, $options); return $this; @@ -649,6 +660,7 @@ class ActiveField extends Component public function radioList($items, $options = []) { $this->adjustLabelFor($options); + $this->_skipLabelFor = true; $this->parts['{input}'] = Html::activeRadioList($this->model, $this->attribute, $items, $options); return $this;