Skip to content

Commit

Permalink
Remove for attributes for other group type inputs.
Browse files Browse the repository at this point in the history
date/time/datetime inputs have long had their for attributes wrong as
well. Lump them in with other group type inputs that no longer get for
attributes that are just wrong.
  • Loading branch information
markstory committed Oct 29, 2014
1 parent 2b1a479 commit 5e1ddf6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/View/Helper/FormHelper.php
Expand Up @@ -1233,7 +1233,8 @@ 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)) {
$groupTypes = ['radio', 'multicheckbox', 'date', 'time', 'datetime'];
if (in_array($options['type'], $groupTypes, true)) {
$labelAttributes['for'] = false;
}
if ($options['nestedInput']) {
Expand Down
11 changes: 5 additions & 6 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -2416,7 +2416,7 @@ public function testInputDatetime() {
));
$expected = array(
'div' => array('class' => 'input datetime'),
'label' => array('for' => 'prueba'),
'<label',
'Prueba',
'/label',
'This is it!',
Expand Down Expand Up @@ -2458,7 +2458,7 @@ public function testInputDatetimeIdPrefix() {
));
$expected = array(
'div' => array('class' => 'input datetime'),
'label' => array('for' => 'prefix-prueba'),
'<label',
'Prueba',
'/label',
'This is it!',
Expand Down Expand Up @@ -4788,15 +4788,14 @@ public function testFormDateTimeMulti() {
* @return void
*/
public function testDateTimeLabelIdMatchesFirstInput() {
$this->markTestIncomplete('Need to revisit once models work again.');
$result = $this->Form->input('Model.date', array('type' => 'date'));
$this->assertContains('label for="ModelDateMonth"', $result);
$this->assertContains('<label>Date</label>', $result);

$result = $this->Form->input('Model.date', array('type' => 'date', 'dateFormat' => 'DMY'));
$this->assertContains('label for="ModelDateDay"', $result);
$this->assertContains('<label>Date</label>', $result);

$result = $this->Form->input('Model.date', array('type' => 'date', 'dateFormat' => 'YMD'));
$this->assertContains('label for="ModelDateYear"', $result);
$this->assertContains('<label>Date</label>', $result);
}

/**
Expand Down

0 comments on commit 5e1ddf6

Please sign in to comment.