Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

label_for when used with tag_field missing id attribute #932

Closed
chy-causer opened this issue Mar 8, 2016 · 1 comment
Closed

label_for when used with tag_field missing id attribute #932

chy-causer opened this issue Mar 8, 2016 · 1 comment

Comments

@chy-causer
Copy link

According to the HTML5 spec, when a label tag contains a for attribute it must accompany a labelable element of matching id. This is to aid usability of forms in browsers as well as to help screen readers.

The following commit adds a failing test that should hopefully explain what I mean:
chy-causer@c4f43e7

I used Mojo::DOM in the test rather than hard-coded the id and for attributes directly because a fully working solution could possibly have to rewrite these attributes. A naive solution of

%= label_for foo => '<Foo>'
%= text_field foo => 'bar'

<label for="foo">&lt;Foo&gt;</label>
<input name="foo" id="foo" type="text" value="bar"> 

may well break HTML validation on existing sites whenever multiple fields for name foo are rendered on a page.

It is possible that this is an intractable problem, and if so, may I please request a short note or example in the docs for label_for and rendering guides indicating that when label_for is used, the input field requires its id attribute to match? I was scratching my head for a bit as to why my label tags were not clickable.

Many thanks.

@kraih kraih closed this as completed in 48c1531 Mar 8, 2016
@kraih
Copy link
Member

kraih commented Mar 8, 2016

Thanks, fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants