observe_field and radio buttons
Posted by Tim Riley Tue, 14 Mar 2006 05:20:00 GMT
Without specifying any extra options for Ruby on Rails’ radio_button or radio_button_tag form tag helpers, each tag will share the same id and name attributes.
While the name attribute needs to be shared for a set of radio buttons to work properly, sharing the id attribute is not necessary and will also break the observe_field JavaScript helper. In this case, the field observer will only be triggered for any events in the first of the radio buttons with the specified id.
Fortunately, you can set the id manually:
<%= radio_button_tag "button_name",
"button_val",
checked,
:id => "my_custom_id" %>
Then, using a separate observer for each radio button in your set with a unique id, you can effectively observe any change in the set. Watch out, radio buttons!