Browse Source

Fix input() making multiple checkboxes.

If you used the new input type name the output would be incorrect and
a notice error would be triggered.
Mark Story 11 years ago
parent
commit
086c88b8e5
2 changed files with 37 additions and 0 deletions
  1. 4 0
      src/View/Helper/FormHelper.php
  2. 33 0
      tests/TestCase/View/Helper/FormHelperTest.php

+ 4 - 0
src/View/Helper/FormHelper.php

@@ -1006,6 +1006,10 @@ class FormHelper extends Helper {
 				$opts = $options['options'];
 				unset($options['options']);
 				return $this->radio($fieldName, $opts, $options);
+			case 'multicheckbox':
+				$opts = $options['options'];
+				unset($options['options']);
+				return $this->multicheckbox($fieldName, $opts, $options);
 			case 'url':
 				$options = $this->_initInputField($fieldName, $options);
 				return $this->widget($options['type'], $options);

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

@@ -4152,6 +4152,39 @@ class FormHelperTest extends TestCase {
 	}
 
 /**
+ * Test that input() works with multicheckbox.
+ *
+ * @return void
+ */
+	public function testInputMultiCheckbox() {
+		$result = $this->Form->input('category', [
+			'type' => 'multicheckbox',
+			'options' => ['1', '2'],
+		]);
+		$expected = [
+			['div' => ['class' => 'input multicheckbox']],
+			['label' => ['for' => 'category']],
+			'Category',
+			'/label',
+			'input' => ['type' => 'hidden', 'name' => 'category', 'value' => ''],
+			['div' => ['class' => 'checkbox']],
+				['label' => ['for' => 'category-0']],
+					['input' => ['type' => 'checkbox', 'name' => 'category[]', 'value' => '0', 'id' => 'category-0']],
+					'1',
+				'/label',
+			'/div',
+			['div' => ['class' => 'checkbox']],
+				['label' => ['for' => 'category-1']],
+					['input' => ['type' => 'checkbox', 'name' => 'category[]', 'value' => '1', 'id' => 'category-1']],
+					'2',
+				'/label',
+			'/div',
+			'/div',
+		];
+		$this->assertHtml($expected, $result);
+	}
+
+/**
  * testCheckbox method
  *
  * Test generation of checkboxes