From 4fc6c872ef1f6ae10eec7c24cbc60697336ca707 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 3 Sep 2006 19:32:31 +0000 Subject: radio_button_tag generates unique id attributes. Closes #3353. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4925 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_view/helpers/form_tag_helper.rb | 3 ++- actionpack/test/template/form_tag_helper_test.rb | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 73a2e6f4fe..fcbb7f3a2f 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* radio_button_tag generates unique id attributes. #3353 [Bob Silva, somekool@gmail.com] + * strip_tags returns nil for a blank arg such as nil or "". #2229 [duncan@whomwah.com] * Cleanup assert_tag :children counting. #2181 [jamie@bravenet.com] diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 816f1064f7..e023fe93d2 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -125,7 +125,8 @@ module ActionView # Creates a radio button. def radio_button_tag(name, value, checked = false, options = {}) - html_options = { "type" => "radio", "name" => name, "id" => name, "value" => value }.update(options.stringify_keys) + pretty_tag_value = value.to_s.gsub(/\s/, "_").gsub(/(?!-)\W/, "").downcase + html_options = { "type" => "radio", "name" => name, "id" => "#{name}_#{pretty_tag_value}", "value" => value }.update(options.stringify_keys) html_options["checked"] = "checked" if checked tag :input, html_options end diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 0e4ac5f5a7..743d75ca8c 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -53,8 +53,21 @@ class FormTagHelperTest < Test::Unit::TestCase def test_radio_button_tag actual = radio_button_tag "people", "david" - expected = %() + expected = %() assert_dom_equal expected, actual + + actual = radio_button_tag("num_people", 5) + expected = %() + assert_dom_equal expected, actual + + actual = radio_button_tag("gender", "m") + radio_button_tag("gender", "f") + expected = %() + assert_dom_equal expected, actual + + actual = radio_button_tag("opinion", "-1") + radio_button_tag("opinion", "1") + expected = %() + assert_dom_equal expected, actual + end def test_select_tag -- cgit v1.2.3