This project is archived and is in readonly mode.

#1992 ✓duplicate
David Stevenson

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

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>

Attachments

Referenced by

Pages