Skip to content

Commit

Permalink
Remove meaningless and possibly wrong for attr.
Browse files Browse the repository at this point in the history
The generated for attribute for input group labels was pretty much
always wrong. Instead of trying to make it correct just omit it.
  • Loading branch information
markstory committed Oct 29, 2014
1 parent c12ac5f commit 2b1a479
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/View/Helper/FormHelper.php
Expand Up @@ -1174,7 +1174,7 @@ protected function _magicOptions($fieldName, $options, $allowOverride) {
* @return bool|string false or Generated label element
*/
protected function _getLabel($fieldName, $options) {
if (in_array($options['type'], ['hidden'])) {
if ($options['type'] === 'hidden') {
return false;
}

Expand Down Expand Up @@ -1233,6 +1233,9 @@ protected function _inputLabel($fieldName, $label, $options) {
$options += ['id' => null, 'input' => null, 'nestedInput' => false];

$labelAttributes['for'] = $options['id'];
if (in_array($options['type'], ['radio', 'multicheckbox'], true)) {
$labelAttributes['for'] = false;
}
if ($options['nestedInput']) {
$labelAttributes['input'] = $options['input'];
}
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -3395,7 +3395,7 @@ public function testInputRadio() {
]);
$expected = [
['div' => ['class' => 'input radio']],
['label' => ['for' => 'test']],
'<label',
'Test',
'/label',
['input' => ['type' => 'hidden', 'name' => 'test', 'value' => '']],
Expand Down Expand Up @@ -4227,7 +4227,7 @@ public function testInputMultiCheckbox() {
]);
$expected = [
['div' => ['class' => 'input multicheckbox']],
['label' => ['for' => 'category']],
'<label',
'Category',
'/label',
'input' => ['type' => 'hidden', 'name' => 'category', 'value' => ''],
Expand Down Expand Up @@ -6405,7 +6405,7 @@ public function testInputsNotNested() {
['label' => ['for' => 'confirm-n']],
'No',
'/label',
['label' => ['for' => 'confirm']],
'<label',
'Confirm',
'/label',
'/div',
Expand Down

0 comments on commit 2b1a479

Please sign in to comment.