Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

f.label should work for targeting f.radio_button

#1992

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.

Reported by David Stevenson · February 16th, 2009 @ 07:26 PM

State: duplicate
Milestone: 2.x
Assigned to: nobody
Importance: none