Wrapping <%= f.check_box %> inside <label>
- by Ben Scheirman
I have a list of checkboxes on a form. Due to the way the CSS is structured, the label element is styled directly. This requires me to nest the checkbox inside of the tag.
This works in raw HTML, if you click on the label text, the state of the checkbox changes. It doesn't work with the rails <%= f.check_box %> helper, however, because it outputs a hidden input tag first.
In summary,
<label>
<%= f.check_box :foo %>
Foo
</label>
this is the output I want:
<label>
<input type="checkbox" ... />
<input type="hidden" ... />
Foo
</label>
...but this is what rails is giving me:
<label>
<input type="hidden" ... />
<input type="checkbox" ... />
Foo
</label>
So the label behavior doesn't actually work :(.
Is there any way to get around this?