This project is archived and is in readonly mode.
f.label should work for targeting f.radio_button
Reported by David Stevenson | February 16th, 2009 @ 07:26 PM | in 2.x
It's impossible to automatically generate a label for a radio button using a form helper. The for="" attribute of a label tag cannot be generated with the same ID of a radio button:
- Radio button ID looks like "model_attribute_value1"
- Label for attribute looks like "model_attribute"
I suggest that the "label" method take an optional value attribute like so:
- f.radio_button :attribute, "value1"
- f.label :attribute, "Select value1", :value => "value1"
Additionally, the code should be refactored so that the code which generates the ID "model_attribute_value1" is only in one place and is consistent.
Comments and changes to this ticket
-
David Stevenson February 16th, 2009 @ 08:00 PM
- Tag changed from activerecord, form_helper, label, radio_button to activerecord, form_helper, label, patch, radio_button
Attaching patch complete with test.
-
Michael Koziarski March 2nd, 2009 @ 05:42 AM
- State changed from new to duplicate
this isn't strictly a 'duplicate' of #1993, but the two patches clash and both are good
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 1993 f.radio_button ignores parent fields_for's :index option This looks good to me, can you combine it with #1992 and ...