Browse Source

Remove for attributes for other group type inputs.

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.
Mark Story 11 years ago
parent
commit
5e1ddf6dcf
2 changed files with 7 additions and 7 deletions
  1. 2 1
      src/View/Helper/FormHelper.php
  2. 5 6
      tests/TestCase/View/Helper/FormHelperTest.php

+ 2 - 1
src/View/Helper/FormHelper.php

@@ -1233,7 +1233,8 @@ class FormHelper extends Helper {
 		$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']) {

+ 5 - 6
tests/TestCase/View/Helper/FormHelperTest.php

@@ -2416,7 +2416,7 @@ class FormHelperTest extends TestCase {
 		));
 		$expected = array(
 			'div' => array('class' => 'input datetime'),
-			'label' => array('for' => 'prueba'),
+			'<label',
 			'Prueba',
 			'/label',
 			'This is it!',
@@ -2458,7 +2458,7 @@ class FormHelperTest extends TestCase {
 		));
 		$expected = array(
 			'div' => array('class' => 'input datetime'),
-			'label' => array('for' => 'prefix-prueba'),
+			'<label',
 			'Prueba',
 			'/label',
 			'This is it!',
@@ -4788,15 +4788,14 @@ class FormHelperTest extends TestCase {
  * @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);
 	}
 
 /**