From 062c30d12587015c6373dd78336d7a43d32a086e Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Jakub=20Ku=C5=BAma?= Date: Sat, 22 Nov 2008 14:04:12 +0100 Subject: [PATCH] check_box_tag should behave like radio_button_tag --- .../lib/action_view/helpers/form_tag_helper.rb | 20 +++++++++----------- actionpack/test/template/form_tag_helper_test.rb | 8 ++++---- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 4646bc1..c133f54 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -117,7 +117,7 @@ module ActionView # Creates a label field # - # ==== Options + # ==== Options # * Creates standard HTML attributes for the tag. # # ==== Examples @@ -268,21 +268,21 @@ module ActionView # # ==== Examples # check_box_tag 'accept' - # # => + # # => # # check_box_tag 'rock', 'rock music' - # # => + # # => # # check_box_tag 'receive_email', 'yes', true - # # => + # # => # # check_box_tag 'tos', 'yes', false, :class => 'accept_tos' - # # => + # # => # # check_box_tag 'eula', 'accepted', false, :disabled => true - # # => + # # => def check_box_tag(name, value = "1", checked = false, options = {}) - html_options = { "type" => "checkbox", "name" => name, "id" => sanitize_to_id(name), "value" => value }.update(options.stringify_keys) + html_options = { "type" => "checkbox", "name" => name, "id" => sanitize_to_id("#{name}_#{value}"), "value" => value }.update(options.stringify_keys) html_options["checked"] = "checked" if checked tag :input, html_options end @@ -307,9 +307,7 @@ module ActionView # radio_button_tag 'color', "green", true, :class => "color_input" # # => 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}_#{value}"), "value" => value }.update(options.stringify_keys) html_options["checked"] = "checked" if checked tag :input, html_options end @@ -351,7 +349,7 @@ module ActionView if disable_with = options.delete("disable_with") disable_with = "this.value='#{disable_with}'" disable_with << ";#{options.delete('onclick')}" if options['onclick'] - + options["onclick"] = "if (window.hiddenCommit) { window.hiddenCommit.setAttribute('value', this.value); }" options["onclick"] << "else { hiddenCommit = this.cloneNode(false);hiddenCommit.setAttribute('type', 'hidden');this.form.appendChild(hiddenCommit); }" options["onclick"] << "this.setAttribute('originalValue', this.value);this.disabled = true;#{disable_with};" diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 0c8af60..a98803a 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -16,7 +16,7 @@ class FormTagHelperTest < ActionView::TestCase def test_check_box_tag actual = check_box_tag "admin" - expected = %() + expected = %() assert_dom_equal expected, actual end @@ -236,8 +236,8 @@ class FormTagHelperTest < ActionView::TestCase end def test_boolean_options - assert_dom_equal %(), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes") - assert_dom_equal %(), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil) + assert_dom_equal %(), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes") + assert_dom_equal %(), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil) assert_dom_equal %(), tag(:input, :type => "checkbox", :checked => false) assert_dom_equal %(), select_tag("people", "", :multiple => true) assert_dom_equal %(), select_tag("people[]", "", :multiple => true) @@ -270,7 +270,7 @@ class FormTagHelperTest < ActionView::TestCase submit_tag("Save", :confirm => "Are you sure?") ) end - + def test_image_submit_tag_with_confirmation assert_dom_equal( %(), -- 1.5.6.3