From 211ffd3f792d2d0823365bdb49d29b9f7ed99ca0 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 9 Oct 2006 00:53:59 +0000 Subject: Fixed that FormHelper#radio_button didn't respect an :id being passed in (closes #6266) [evansj] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5247 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_view/helpers/form_helper.rb | 4 ++-- actionpack/test/template/form_helper_test.rb | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 41f71cc68c..224874188d 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed that FormHelper#radio_button didn't respect an :id being passed in #6266 [evansj] + * Added an html_options hash parameter to javascript_tag() and update_page_tag() helpers #6311 [tzaharia]. Example: update_page_tag :defer => 'true' { |page| ... } diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index f9baed69a9..4bc5a8d254 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -269,9 +269,9 @@ module ActionView else checked = self.class.radio_button_checked?(value(object), tag_value) end - options["checked"] = "checked" if checked + options["checked"] = "checked" if checked pretty_tag_value = tag_value.to_s.gsub(/\s/, "_").gsub(/\W/, "").downcase - options["id"] = defined?(@auto_index) ? + options["id"] ||= defined?(@auto_index) ? "#{@object_name}_#{@auto_index}_#{@method_name}_#{pretty_tag_value}" : "#{@object_name}_#{@method_name}_#{pretty_tag_value}" add_default_name_and_id(options) diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 95d52a30b6..14605b8abc 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -120,6 +120,12 @@ class FormHelperTest < Test::Unit::TestCase radio_button("post", "secret", "1") ) end + + def test_radio_button_respects_passed_in_id + assert_dom_equal('', + radio_button("post", "secret", "1", :id=>"foo") + ) + end def test_text_area assert_dom_equal( -- cgit v1.2.3