From f7862c16c7eede8e6964883666759043e9a39dbc Mon Sep 17 00:00:00 2001 From: Evgeniy Moiseenko Date: Mon, 17 Sep 2018 02:26:42 +0300 Subject: [PATCH] Fixes #14368: Added `role` attribute for active radio list --- framework/CHANGELOG.md | 1 + framework/widgets/ActiveField.php | 14 ++++++++++++++ tests/framework/widgets/ActiveFieldTest.php | 14 ++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 6c3626452d..d8680832b9 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -4,6 +4,7 @@ Yii Framework 2 Change Log 2.0.16 under development ------------------------ +- Bug #14368: Added `role` attribute for active radio list (s1lver) - Bug #16680: Fixed ActiveField 'text' input with maxlength (s1lver) - Bug #5341: HasMany via two relations (shirase, cebe) - Bug #16558: Added cloning `yii\data\ActiveDataProvider::query` property when ActiveDataProvider object is cloned (mgrechanik) diff --git a/framework/widgets/ActiveField.php b/framework/widgets/ActiveField.php index 381aaeb15c..50a18e2fc1 100644 --- a/framework/widgets/ActiveField.php +++ b/framework/widgets/ActiveField.php @@ -728,6 +728,7 @@ class ActiveField extends Component $this->addErrorClassIfNeeded($options); } + $this->addRoleAttributes($options, 'radiogroup'); $this->addAriaAttributes($options); $this->adjustLabelFor($options); $this->_skipLabelFor = true; @@ -923,6 +924,19 @@ class ActiveField extends Component } } + /** + * Add role attributes to the input options + * @param $options array input options + * @param string $role + * @since 2.0.16 + */ + protected function addRoleAttributes(&$options, $role) + { + if (!isset($options['role'])) { + $options['role'] = $role; + } + } + /** * Adds validation class to the input options if needed. * @param $options array input options diff --git a/tests/framework/widgets/ActiveFieldTest.php b/tests/framework/widgets/ActiveFieldTest.php index daf346c40b..9b3d32b5ec 100644 --- a/tests/framework/widgets/ActiveFieldTest.php +++ b/tests/framework/widgets/ActiveFieldTest.php @@ -353,6 +353,20 @@ EOD; $this->assertEqualsWithoutLE($expectedValue, $this->activeField->parts['{input}']); } + public function testRadioList() + { + $expectedValue = <<<'EOD' +
+ +
+
Hint for attributeName attribute
+
+
+EOD; + $this->activeField->radioList(['1' => 'Item One']); + $this->assertEqualsWithoutLE($expectedValue, $this->activeField->render()); + } + public function testGetClientOptionsReturnEmpty() { // setup: we want the real deal here!