accessibility - Why should HTML validators care about two inputs within a label, if one of them is of type hidden? -


consider following markup:

<label>   <input type="hidden" name="likes_bacon" value="no" />   <input type="checkbox" name="likes_bacon" value="yes" />   bacon </label> 

the w3c html validator raise error against markup label contains more 1 input, technically invalid.

my question 2 fold: why should validator care, since first hidden? user agents (including screen readers - i've checked) not make indication hidden field exists, , it's quite common/useful frameworks render checkboxes accompanying hidden input same name in order pass through default value in form submission in cases form submitted checkbox unchecked. hidden input immutable since not really user-editable form control.

secondly, aside possibility of error showing in browser consoles , failing validation, is there harm in doing this? can't think of single reason other "you're not supposed to"!

i guess leads on wider point perhaps input type="hidden" misnomer, not input @ all!

i'm aware it's entirely possible move inputs outside of label , reference checkbox id for attribute.

loosely related: two input fields inside 1 label

why w3c validator says not valid? because not valid! plain , simple. html specification says:

the label element may contain @ one descendant input element, button element, select element, or textarea element.

since spec says invalid, validator invalid.

now, reason why specification says because clicking on label focuses interactive element associated it. when element has focus can receive keyboard input.

by unspoken user interface standards, can type in one text box @ time. since can type in 1 text box, one form control needs receive keyboard input @ time. because of that, there one interactive html element focus @ time.

there no point focusing 2 elements @ once label, since there can 1 receiving keyboard input.

there no point putting hidden input inside label, way. since hidden inputs not manipulated user, there no point giving keyboard input them.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -