Przeglądaj źródła

ZF-12059: MultiCheckbox should not use "for" attribute on main label tag

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24963 44c647ce-9c0f-0410-b52a-842ac1e357ba
adamlundrigan 13 lat temu
rodzic
commit
554c67a0cc

+ 21 - 0
library/Zend/Form/Element/MultiCheckbox.php

@@ -49,4 +49,25 @@ class Zend_Form_Element_MultiCheckbox extends Zend_Form_Element_Multi
      * @var bool
      */
     protected $_isArray = true;
+
+    /**
+     * Load default decorators
+     *
+     * @return Zend_Form_Element_MultiCheckbox
+     */
+    public function loadDefaultDecorators()
+    {
+        if ($this->loadDefaultDecoratorsIsDisabled()) {
+            return $this;
+        }
+
+        parent::loadDefaultDecorators();
+
+        // Disable 'for' attribute
+        if (false !== $decorator = $this->getDecorator('label')) {
+            $decorator->setOption('disableFor', true);
+        }
+
+        return $this;
+    }
 }

+ 28 - 0
tests/Zend/Form/Element/MultiCheckboxTest.php

@@ -317,6 +317,34 @@ class Zend_Form_Element_MultiCheckboxTest extends PHPUnit_Framework_TestCase
         $this->assertTrue(is_array($messages), 'Expected error message');
         $this->assertArrayHasKey('isEmpty', $messages, 'Expected \'isEmpty\' error message');
     }
+
+    /**
+     * @group ZF-12059
+     */
+    public function testDisabledForAttribute()
+    {
+        $this->element->setLabel('Foo');
+
+        $expected = '<dt id="foo-label"><label class="optional">Foo</label></dt>'
+                  . "\n"
+                  . '<dd id="foo-element">'
+                  . "\n"
+                  . '</dd>';
+        $this->assertSame($expected, $this->element->render($this->getView()));
+    }
+
+    /**
+     * @group ZF-12059
+     */
+    public function testDisabledForAttributeWithoutLabelDecorator()
+    {
+        $this->element->setLabel('Foo')->removeDecorator('label');
+
+        $expected = '<dd id="foo-element">'
+                  . "\n"
+                  . '</dd>';
+        $this->assertSame($expected, $this->element->render($this->getView()));
+    }
 }
 
 // Call Zend_Form_Element_MultiCheckboxTest::main() if this source file is executed directly.