Skip to content

Commit

Permalink
Modify the behavior of radio_button_tag to use sanitize_to_id for…
Browse files Browse the repository at this point in the history
… consistency [#1792 status:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
sikachu authored and josevalim committed Feb 2, 2010
1 parent ea2cbc8 commit c01014a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 1 addition & 3 deletions actionpack/lib/action_view/helpers/form_tag_helper.rb
Expand Up @@ -329,9 +329,7 @@ def check_box_tag(name, value = "1", checked = false, options = {})
# radio_button_tag 'color', "green", true, :class => "color_input"
# # => <input checked="checked" class="color_input" id="color_green" name="color" type="radio" value="green" />
def radio_button_tag(name, value, checked = false, options = {})
pretty_tag_value = value.to_s.gsub(/\s/, "_").gsub(/(?!-)\W/, "").downcase
pretty_name = name.to_s.gsub(/\[/, "_").gsub(/\]/, "")
html_options = { "type" => "radio", "name" => name, "id" => "#{pretty_name}_#{pretty_tag_value}", "value" => value }.update(options.stringify_keys)
html_options = { "type" => "radio", "name" => name, "id" => "#{sanitize_to_id(name)}_#{sanitize_to_id(value)}", "value" => value }.update(options.stringify_keys)
html_options["checked"] = "checked" if checked
tag :input, html_options
end
Expand Down
4 changes: 4 additions & 0 deletions actionpack/test/template/form_tag_helper_test.rb
Expand Up @@ -120,6 +120,10 @@ def test_radio_button_tag
actual = radio_button_tag("person[gender]", "m")
expected = %(<input id="person_gender_m" name="person[gender]" type="radio" value="m" />)
assert_dom_equal expected, actual

actual = radio_button_tag('ctrlname', 'apache2.2')
expected = %(<input id="ctrlname_apache2.2" name="ctrlname" type="radio" value="apache2.2" />)
assert_dom_equal expected, actual
end

def test_select_tag
Expand Down

0 comments on commit c01014a

Please sign in to comment.