This project is archived and is in readonly mode.
to_radio_button_tag ignores :index options partially
Reported by Jeroen van Dijk | April 1st, 2009 @ 02:59 PM | in 2.3.4
When the form_builder method #radio_button is given the :index option it gets ignored for the id of the radio button. The :index option is necessary when using nested forms with new and existing attributes.
The consequence is that you get html elements with duplicate id's and labels won't work with those elements because they do get the index.
The cause is visible in the #to_radio_button:
def to_radio_button_tag(tag_value, options = {})
options = DEFAULT_RADIO_OPTIONS.merge(options.stringify_keys)
options["type"] = "radio"
options["value"] = tag_value
if options.has_key?("checked")
cv = options.delete "checked"
checked = cv == true || cv == "checked"
else
checked = self.class.radio_button_checked?(value(object), tag_value)
end
options["checked"] = "checked" if checked
pretty_tag_value = tag_value.to_s.gsub(/\s/, "_").gsub(/\W/, "").downcase
options["id"] ||= defined?(@auto_index) ? ## <--- PROBLEM IS IN HERE!
"#{tag_id_with_index(@auto_index)}_#{pretty_tag_value}" :
"#{tag_id}_#{pretty_tag_value}"
add_default_name_and_id(options)
tag("input", options)
end
Normally the index option is processed in #add_default_name_and_id but because :id already has been set this is not working.
I dont understand the logic and when I have time I will try to see if I can find it from the additional tests.
Comments and changes to this ticket
-
José Valim April 2nd, 2009 @ 10:26 PM
Jeroen,
Just found that too. Here is a patch with tests. If possible, try it and see if it solves for you too.
-
José Valim July 19th, 2009 @ 01:31 PM
- Assigned user set to Eloy Duran
Assigning it to Eloy since this error appears when working with nested attributes.
-
Eloy Duran July 21st, 2009 @ 07:51 AM
- Milestone changed from 2.x to 2.3.4
I'm still travelling through Japan, but I will definitely be able to apply this to my 2.3.4 branch. Thanks.
-
José Valim July 23rd, 2009 @ 10:49 PM
Actually, this appears to be the same as #1993. I would stick with #1993 since the patch solves two issues:
https://rails.lighthouseapp.com/projects/8994/tickets/1993-fradio_b...
-
Eloy Duran July 24th, 2009 @ 02:44 AM
- State changed from new to duplicate
Thanks for investigating José!
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
- 2391 Allow strings to be sent as collection to select Thanks Eloy! You would like to check #2392 as well, it's ...