mirror of
https://github.com/github/rails.git
synced 2026-01-30 08:48:06 -05:00
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
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -53,8 +53,21 @@ class FormTagHelperTest < Test::Unit::TestCase
|
||||
|
||||
def test_radio_button_tag
|
||||
actual = radio_button_tag "people", "david"
|
||||
expected = %(<input id="people" name="people" type="radio" value="david" />)
|
||||
expected = %(<input id="people_david" name="people" type="radio" value="david" />)
|
||||
assert_dom_equal expected, actual
|
||||
|
||||
actual = radio_button_tag("num_people", 5)
|
||||
expected = %(<input id="num_people_5" name="num_people" type="radio" value="5" />)
|
||||
assert_dom_equal expected, actual
|
||||
|
||||
actual = radio_button_tag("gender", "m") + radio_button_tag("gender", "f")
|
||||
expected = %(<input id="gender_m" name="gender" type="radio" value="m" /><input id="gender_f" name="gender" type="radio" value="f" />)
|
||||
assert_dom_equal expected, actual
|
||||
|
||||
actual = radio_button_tag("opinion", "-1") + radio_button_tag("opinion", "1")
|
||||
expected = %(<input id="opinion_-1" name="opinion" type="radio" value="-1" /><input id="opinion_1" name="opinion" type="radio" value="1" />)
|
||||
assert_dom_equal expected, actual
|
||||
|
||||
end
|
||||
|
||||
def test_select_tag
|
||||
|
||||
Reference in New Issue
Block a user