From 6ba750f81a23cdf5072f8ac3c5ff0f834c43931d Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Thu, 30 Aug 2012 12:28:44 +0200 Subject: [PATCH 1/3] Fix type for multicheckbox Fix type for multicheckbox and add unit tests --- library/Zend/Form/Element/MultiCheckbox.php | 9 +++++++++ tests/ZendTest/Form/View/Helper/FormElementTest.php | 3 +++ 2 files changed, 12 insertions(+) diff --git a/library/Zend/Form/Element/MultiCheckbox.php b/library/Zend/Form/Element/MultiCheckbox.php index 33f4d1c7e97..ac53f17f32d 100644 --- a/library/Zend/Form/Element/MultiCheckbox.php +++ b/library/Zend/Form/Element/MultiCheckbox.php @@ -21,6 +21,15 @@ */ class MultiCheckbox extends Checkbox { + /** + * Seed attributes + * + * @var array + */ + protected $attributes = array( + 'type' => 'multi_checkbox' + ); + /** * @var bool */ diff --git a/tests/ZendTest/Form/View/Helper/FormElementTest.php b/tests/ZendTest/Form/View/Helper/FormElementTest.php index b86fe15c34f..6b9931c46e8 100644 --- a/tests/ZendTest/Form/View/Helper/FormElementTest.php +++ b/tests/ZendTest/Form/View/Helper/FormElementTest.php @@ -112,10 +112,13 @@ public function testRendersMultiElementsAsExpected($type, $inputType, $additiona { if ($type === 'radio') { $element = new Element\Radio('foo'); + $this->assertEquals('radio', $element->getAttribute('type')); } elseif ($type === 'multi_checkbox') { $element = new Element\MultiCheckbox('foo'); + $this->assertEquals('multi_checkbox', $element->getAttribute('type')); } elseif ($type === 'select') { $element = new Element\Select('foo'); + $this->assertEquals('select', $element->getAttribute('type')); } else { $element = new Element('foo'); } From 10a727409c714f81a9f9a624b620a42fdb446fc4 Mon Sep 17 00:00:00 2001 From: Koen Pieters Date: Thu, 30 Aug 2012 13:59:44 +0200 Subject: [PATCH 2/3] Form\Element\MultiCheckbox removed 'multicheckbox' as a type. Set multi_checbox as default attribute type. Added unit test --- library/Zend/Form/Element/MultiCheckbox.php | 9 +++++++++ library/Zend/Form/View/Helper/FormRow.php | 2 +- tests/ZendTest/Form/Element/MultiCheckboxTest.php | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/library/Zend/Form/Element/MultiCheckbox.php b/library/Zend/Form/Element/MultiCheckbox.php index 33f4d1c7e97..620df92337f 100644 --- a/library/Zend/Form/Element/MultiCheckbox.php +++ b/library/Zend/Form/Element/MultiCheckbox.php @@ -21,6 +21,15 @@ */ class MultiCheckbox extends Checkbox { + /** + * Seed attributes + * + * @var array + */ + protected $attributes = array( + 'type' => 'multi_checkbox', + ); + /** * @var bool */ diff --git a/library/Zend/Form/View/Helper/FormRow.php b/library/Zend/Form/View/Helper/FormRow.php index 631f8f341fe..2eac6438836 100644 --- a/library/Zend/Form/View/Helper/FormRow.php +++ b/library/Zend/Form/View/Helper/FormRow.php @@ -82,7 +82,7 @@ public function render(ElementInterface $element) // Multicheckbox elements have to be handled differently as the HTML standard does not allow nested // labels. The semantic way is to group them inside a fieldset $type = $element->getAttribute('type'); - if ($type === 'multi_checkbox' || $type === 'multicheckbox' || $type === 'radio') { + if ($type === 'multi_checkbox' || $type === 'radio') { $markup = sprintf( '
%s%s
', $label, diff --git a/tests/ZendTest/Form/Element/MultiCheckboxTest.php b/tests/ZendTest/Form/Element/MultiCheckboxTest.php index b7bc9a0584c..42208ce1a4e 100644 --- a/tests/ZendTest/Form/Element/MultiCheckboxTest.php +++ b/tests/ZendTest/Form/Element/MultiCheckboxTest.php @@ -104,4 +104,13 @@ public function testInArrayValidationOfOptions($valueTests, $options) $this->assertInstanceOf('Zend\Validator\Explode', $explodeValidator); $this->assertTrue($explodeValidator->isValid($valueTests)); } + + public function testAttributeType() + { + $element = new MultiCheckboxElement(); + $attributes = $element->getAttributes(); + + $this->assertArrayHasKey('type', $attributes); + $this->assertEquals('multi_checkbox', $attributes['type']); + } } \ No newline at end of file From bd8f89b000f2b713a232eeaee0adc9d72f0dfdeb Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Thu, 30 Aug 2012 15:02:14 -0500 Subject: [PATCH 3/3] [#2272][#2269][ZF2-505] Updated README - Noted fix for multi-checkbox rendering --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index fc6bfe642b5..8d4058fe841 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ XX August 2012 - Zend\Di - Fixes ArrayDefinition and ClassDefinition hasMethods() methods to return boolean values. +- Zend\Form + - Fixes issue with multi-checkbox rendering. - Zend\Ldap - Fixes an error nesting condition - Zend\Log