Bugzilla – Bug 755
Validator considers hidden inputs unlabelable
Last modified: 2010-11-22 11:54:54 CET
When labeling a hidden input element in an HTML 5 document, the validator returns the following error: "The for attribute of the label element must refer to a form control." At the very least, the message is misleading, as the input element in the following snippet is certainly a form control: <!DOCTYPE html> <html lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title> Ask a Question | Firefox Support </title> </head> <body> <form action="dummy" method="post"> <input id="id_thingy" type="hidden" name="dummy" value="" /> <label for="id_thingy"> Question </label> </form> </body> </html> It turns out that the validator thinks you can't label hidden inputs: changing the above to type="text" removes the error. However, according to http://www.w3.org/TR/html5/forms.html#the-label-element, one can label any "labelable form-associated element", one of which is "input". I couldn't find any exceptions to this, for example at http://www.w3.org/TR/html5/states-of-the-type-attribute.html#hidden-state. On an aside, since the defined behavior of <label> is to pass its focus on to the labeled element and since hidden elements cannot receive focus, perhaps the HTML 5 spec should consider hidden inputs unlabelable. However however, since labelability is mentioned right after a sentence about how "If the type attribute is *not* in the Hidden state..." at http://www.w3.org/TR/html5/the-input-element.html#the-input-element, I suspect this was considered and dismissed. In summary, I suggest we either change the validator's error message, allow hidden inputs to be labeled, and/or make clear the labelability of hidden inputs in the HTML 5 spec. Best regards, Erik Rose Web Developer : support.mozilla.com
this check is currently done by the Java Schematron-workalike code. I'll take a look at the code today. But it should be a simple fix, so if somebody cares to take a look at the code in the mean time and submit a patch, the current source is here: https://whattf.svn.cvsdude.com/syntax/trunk/non-schema/java/src/org/whattf/checker/schematronequiv/Assertions.java
(In reply to comment #0) > It turns out that the validator thinks you can't label hidden inputs: changing > the above to type="text" removes the error. However, according to > http://www.w3.org/TR/html5/forms.html#the-label-element, one can label any > "labelable form-associated element", one of which is "input". I couldn't find > any exceptions to this, for example at > http://www.w3.org/TR/html5/states-of-the-type-attribute.html#hidden-state. > > On an aside, since the defined behavior of <label> is to pass its focus on to > the labeled element and since hidden elements cannot receive focus, perhaps the > HTML 5 spec should consider hidden inputs unlabelable. However however, since > labelability is mentioned right after a sentence about how "If the type > attribute is *not* in the Hidden state..." at > http://www.w3.org/TR/html5/the-input-element.html#the-input-element, I suspect > this was considered and dismissed. There is also the following statement: http://dev.w3.org/html5/spec/editing.html#the-hidden-attribute [[ Elements that are not hidden should not link to or refer to elements that are hidden. For example, it would be incorrect to use the href attribute to link to a section marked with the hidden attribute. If the content is not applicable or relevant, then there is no reason to link to it. ]] > In summary, I suggest we either change the validator's error message, allow > hidden inputs to be labeled, and/or make clear the labelability of hidden > inputs in the HTML 5 spec. We could change the validator error message to read, "The for attribute of the label element must refer to a *non-hidden* form control.", and I suppose some clarification could also be added in the section of the spec that defines the label attribute and/or the input attribute. By the way, a quick look at the relevant part of the v.nu code shows that the change to make hidden input elements labelable is dead simple -- but it currently making them unlabelable intentionally, I think because of the "should not link to or refer to elements that are hidden" constraint in the spec, so it should not be changed until we get clarification about what the spec says (or should be saying) here.
(In reply to comment #2) > There is also the following statement: > > http://dev.w3.org/html5/spec/editing.html#the-hidden-attribute um, er... pretend I never mentioned that (since it's about the hidden attribute and not the type=hidden state on input, and so has no relevance to this bug...) Anyway, I pinged Hixie about it on IRC: http://krijnhoetmer.nl/irc-logs/whatwg/20100713#l-415 # [08:50] <MikeSmith> Hixie: v.nu code currently doesn't try input/@type=hidden as labelable # [08:50] <Hixie> makes sense # [08:50] <MikeSmith> OK # [08:50] <Hixie> what with <input type=hidden> being hidden and all # [08:50] <MikeSmith> heh # [08:50] <MikeSmith> yeah # [08:50] <Hixie> not sure it's supported by the spec yet # [08:50] <MikeSmith> right # [08:50] <Hixie> but if it's not that's a spec bug imho # [08:51] <MikeSmith> OK # [08:51] <MikeSmith> I'll either raise it myself or ask the v.nu bug commenter to So Erik, can you either go ahead and raise a bug for it at: http://www.w3.org/Bugs/Public/enter_bug.cgi?product=HTML%20WG&component=HTML5%20spec%20%28editor%3A%20Ian%20Hickson%29&priority=P3 ...or let me know, and I'll go ahead and raise one
Bug opened: http://www.w3.org/Bugs/Public/show_bug.cgi?id=10146. Thanks! I'll let you close this as you see fit.
per comment 4, moving this to resolved=wontfix in anticipation of a change to the HTML5 spec Erik, thanks much