diff options
Diffstat (limited to 'actionpack/lib/action_view/helpers')
-rw-r--r-- | actionpack/lib/action_view/helpers/tags/base.rb | 9 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/tags/check_box.rb | 12 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/tags/radio_button.rb | 12 |
3 files changed, 14 insertions, 19 deletions
diff --git a/actionpack/lib/action_view/helpers/tags/base.rb b/actionpack/lib/action_view/helpers/tags/base.rb index c50c7716d4..9f026f69b1 100644 --- a/actionpack/lib/action_view/helpers/tags/base.rb +++ b/actionpack/lib/action_view/helpers/tags/base.rb @@ -47,6 +47,15 @@ module ActionView nil end + def input_checked?(object, options) + if options.has_key?("checked") + checked = options.delete "checked" + checked == true || checked == "checked" + else + checked?(value(object)) + end + end + def retrieve_autoindex(pre_match) object = self.object || @template_object.instance_variable_get("@#{pre_match}") if object && object.respond_to?(:to_param) diff --git a/actionpack/lib/action_view/helpers/tags/check_box.rb b/actionpack/lib/action_view/helpers/tags/check_box.rb index 55574e6f06..2cdc13524b 100644 --- a/actionpack/lib/action_view/helpers/tags/check_box.rb +++ b/actionpack/lib/action_view/helpers/tags/check_box.rb @@ -12,21 +12,15 @@ module ActionView options = @options.stringify_keys options["type"] = "checkbox" options["value"] = @checked_value + options["checked"] = "checked" if input_checked?(object, options) - if options.has_key?("checked") - cv = options.delete "checked" - checked = cv == true || cv == "checked" - else - checked = check_box_checked?(value(object)) - end - - options["checked"] = "checked" if checked if options["multiple"] add_default_name_and_id_for_value(@checked_value, options) options.delete("multiple") else add_default_name_and_id(options) end + hidden = @unchecked_value ? tag("input", "name" => options["name"], "type" => "hidden", "value" => @unchecked_value, "disabled" => options["disabled"]) : "" checkbox = tag("input", options) hidden + checkbox @@ -34,7 +28,7 @@ module ActionView private - def check_box_checked?(value) + def checked?(value) case value when TrueClass, FalseClass value diff --git a/actionpack/lib/action_view/helpers/tags/radio_button.rb b/actionpack/lib/action_view/helpers/tags/radio_button.rb index 3f6a360928..72edd21662 100644 --- a/actionpack/lib/action_view/helpers/tags/radio_button.rb +++ b/actionpack/lib/action_view/helpers/tags/radio_button.rb @@ -11,22 +11,14 @@ module ActionView options = @options.stringify_keys options["type"] = "radio" options["value"] = @tag_value - - if options.has_key?("checked") - cv = options.delete "checked" - checked = cv == true || cv == "checked" - else - checked = radio_button_checked?(value(object)) - end - - options["checked"] = "checked" if checked + options["checked"] = "checked" if input_checked?(object, options) add_default_name_and_id_for_value(@tag_value, options) tag("input", options) end private - def radio_button_checked?(value) + def checked?(value) value.to_s == @tag_value.to_s end end |