Browse Source

Merge pull request #5000 from cakephp/issue-4991

Fix issue with label=false.
José Lorenzo Rodríguez 11 years ago
parent
commit
4dab0c116c
2 changed files with 26 additions and 1 deletions
  1. 1 1
      src/View/Helper/FormHelper.php
  2. 25 0
      tests/TestCase/View/Helper/FormHelperTest.php

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

@@ -1179,7 +1179,7 @@ class FormHelper extends Helper {
 			$label = $options['label'];
 		}
 
-		if ($label === false && isset($options['input'])) {
+		if ($label === false && $options['type'] === 'checkbox') {
 			return $options['input'];
 		}
 		if ($label === false) {

+ 25 - 0
tests/TestCase/View/Helper/FormHelperTest.php

@@ -5170,6 +5170,22 @@ class FormHelperTest extends TestCase {
 	}
 
 /**
+ * Test the label option being set to false.
+ *
+ * @return void
+ */
+	public function testInputLabelFalse() {
+		$this->Form->create($this->article);
+		$result = $this->Form->input('title', ['label' => false]);
+		$expected = [
+			'div' => ['class' => 'input text required'],
+			'input' => ['type' => 'text', 'required' => 'required', 'id' => 'title', 'name' => 'title'],
+			'/div'
+		];
+		$this->assertHtml($expected, $result);
+	}
+
+/**
  * testInputDateMaxYear method
  *
  * Let's say we want to only allow users born from 2006 to 2008 to register
@@ -6231,6 +6247,15 @@ class FormHelperTest extends TestCase {
 		];
 		$this->assertHtml($expected, $result);
 
+		$result = $this->Form->input('foo', ['type' => 'checkbox', 'label' => false]);
+		$expected = [
+			'div' => ['class' => 'input checkbox'],
+			['input' => ['type' => 'hidden', 'name' => 'foo', 'value' => '0']],
+			['input' => ['type' => 'checkbox', 'name' => 'foo', 'id' => 'foo', 'value' => '1']],
+			'/div'
+		];
+		$this->assertHtml($expected, $result);
+
 		$result = $this->Form->input('confirm', [
 			'type' => 'radio',
 			'options' => ['Y' => 'Yes', 'N' => 'No']