Issues

ZF-12059: multiCheckbox shouldn't use "for" attribute on the main label

Description


Options : opt1
opt2
opt3

In the HTML above, the "for" of the first label should be removed because there is no id="options".

Comments

Actually, the "for" attribute of labels can point to either the id OR the input name. As such, this is still valid and correct -- there is an input named "options".

Are you sure about that ?

The W3C validator reports an error. And from W3C HTML reference :

http://w3.org/TR/1999/… {quote} for : (IDReference) This attribute explicitly associates the label with a form control. When present, the value of this attribute must be the same as the value of the id attribute of the form control in the same document. When absent, the label being defined is associated with the control inside the label element. {quote}

Mea culpa -- this was evidently in older browsers that such support was implemented. Re-opening. It should point to "options-element" in this case.

What is the best location to make this change? My first thought is to do this (in {{Zend_Form_Decorator_Label::getId}}):



Index: library/Zend/Form/Decorator/Label.php
===================================================================
--- library/Zend/Form/Decorator/Label.php       (revision 24746)
+++ library/Zend/Form/Decorator/Label.php       (working copy)
@@ -89,6 +89,9 @@
         if (null === $id) {
             if (null !== ($element = $this->getElement())) {
                 $id = $element->getId();
+                if ($element instanceof Zend_Form_Element_Multi) {
+                    $id .= '-element';
+                }
                 $this->setId($id);
             }
         }

I haven't checked yet to see if this has any unintended consequences, but all Zend_Form and Zend_View tests still pass after the above change.

Patch and unit tests added.

Fixed in trunk r24963

Tests failing on Windows

Patch to fix tests on Windows

This is my mistake! :( Thanks to Martin!

Tests updated. Thanks, Martin!

trunk: r25029 release-1.12: r25030