Issues

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

Issue Type: Bug Created: 2012-02-14T18:13:26.000+0000 Last Updated: 2012-07-31T16:24:35.000+0000 Status: Resolved Fix version(s): - 1.12.0 (27/Aug/12)

Reporter: Jérémy Lajotte (pengu) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Form

  • FixForZF1.12
  • zf-crteam-priority

Related issues: Attachments: - diff.patch

Description

<pre class="highlight">


    Options :
  
  
    opt1<br></br>opt2<br></br>opt3
  

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

Comments

Posted by Matthew Weier O'Phinney (matthew) on 2012-02-14T18:40:09.000+0000

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".

Posted by Jérémy Lajotte (pengu) on 2012-02-14T19:03:32.000+0000

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}

Posted by Matthew Weier O'Phinney (matthew) on 2012-02-14T19:37:10.000+0000

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

Posted by Adam Lundrigan (adamlundrigan) on 2012-05-03T19:11:38.000+0000

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

<pre class="highlight">

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.

Posted by Frank Brückner (frosch) on 2012-05-04T08:18:47.000+0000

Patch and unit tests added.

Posted by Adam Lundrigan (adamlundrigan) on 2012-06-15T14:32:36.000+0000

Fixed in trunk r24963

Posted by Martin Hujer (mhujer) on 2012-07-11T07:07:41.000+0000

Tests failing on Windows

Posted by Martin Hujer (mhujer) on 2012-07-11T07:08:28.000+0000

Patch to fix tests on Windows

Posted by Frank Brückner (frosch) on 2012-07-11T09:20:21.000+0000

This is my mistake! :( Thanks to Martin!

Posted by Adam Lundrigan (adamlundrigan) on 2012-07-31T16:24:35.000+0000

Tests updated. Thanks, Martin!

trunk: r25029 release-1.12: r25030

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts