Validator considers hidden inputs unlabelable

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

Received on Tuesday, 13 July 2010 13:35:06 UTC