Skip to content
This repository
Browse code

Fixed missing id uniqueness in FormTag#radio_button #1207 [Jarkko]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1253 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 98306bed054c320833d9d48229c68da10a38f3d0 1 parent 14860eb
David Heinemeier Hansson authored
2  actionpack/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* Fixed missing id uniqueness in FormTag#radio_button #1207 [Jarkko]
  4
+
3 5
 * Fixed assert_redirected_to to work with :only_path => false #1204 [Alisdair McDiarmid]
4 6
 
5 7
 * Fixed render_partial_collection to output an empty string instead of nil when handed an empty array #1202 [Ryan Carver]
4  actionpack/lib/action_view/helpers/form_helper.rb
@@ -175,6 +175,10 @@ def to_radio_button_tag(tag_value, options = {})
175 175
         options["type"]     = "radio"
176 176
         options["value"]    = tag_value
177 177
         options["checked"]  = "checked" if value == tag_value
  178
+        pretty_tag_value    = tag_value.gsub(/\s/, "_").gsub(/\W/, "").downcase
  179
+        options["id"]       = @auto_index ?             
  180
+          "#{@object_name}_#{@auto_index}_#{@method_name}_#{pretty_tag_value}" :
  181
+          "#{@object_name}_#{@method_name}_#{pretty_tag_value}"
178 182
         add_default_name_and_id(options)
179 183
         tag("input", options)
180 184
       end
8  actionpack/test/template/form_helper_test.rb
@@ -82,10 +82,10 @@ def test_check_box
82 82
   end
83 83
 
84 84
   def test_radio_button
85  
-    assert_equal('<input checked="checked" id="post_title" name="post[title]" type="radio" value="Hello World" />',
  85
+    assert_equal('<input checked="checked" id="post_title_hello_world" name="post[title]" type="radio" value="Hello World" />',
86 86
       radio_button("post", "title", "Hello World")
87 87
     )
88  
-    assert_equal('<input id="post_title" name="post[title]" type="radio" value="Goodbye World" />',
  88
+    assert_equal('<input id="post_title_goodbye_world" name="post[title]" type="radio" value="Goodbye World" />',
89 89
       radio_button("post", "title", "Goodbye World")
90 90
     )
91 91
   end
@@ -166,10 +166,10 @@ def test_auto_index
166 166
       check_box("post[]", "secret")
167 167
     )
168 168
    assert_equal(
169  
-"<input checked=\"checked\" id=\"post_#{pid}_title\" name=\"post[#{pid}][title]\" type=\"radio\" value=\"Hello World\" />",
  169
+"<input checked=\"checked\" id=\"post_#{pid}_title_hello_world\" name=\"post[#{pid}][title]\" type=\"radio\" value=\"Hello World\" />",
170 170
       radio_button("post[]", "title", "Hello World")
171 171
     )
172  
-    assert_equal("<input id=\"post_#{pid}_title\" name=\"post[#{pid}][title]\" type=\"radio\" value=\"Goodbye World\" />",
  172
+    assert_equal("<input id=\"post_#{pid}_title_goodbye_world\" name=\"post[#{pid}][title]\" type=\"radio\" value=\"Goodbye World\" />",
173 173
       radio_button("post[]", "title", "Goodbye World")
174 174
     )
175 175
   end

0 notes on commit 98306be

Please sign in to comment.
Something went wrong with that request. Please try again.