From 7b5ed66122873eebb773a6418f3a94d946cc4f8c Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 19 Dec 2004 11:25:55 +0000 Subject: Added respondence to *_before_type_cast for all attributes to return their string-state before they were type casted by the column type. Added use of *_before_type_cast for all input and text fields. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@215 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/helpers/active_record_helper.rb | 2 -- actionpack/lib/action_view/helpers/form_helper.rb | 14 +++++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'actionpack/lib/action_view/helpers') diff --git a/actionpack/lib/action_view/helpers/active_record_helper.rb b/actionpack/lib/action_view/helpers/active_record_helper.rb index 07ede179e6..6855fa49c5 100644 --- a/actionpack/lib/action_view/helpers/active_record_helper.rb +++ b/actionpack/lib/action_view/helpers/active_record_helper.rb @@ -132,7 +132,6 @@ module ActionView end alias_method :tag_without_error_wrapping, :tag - def tag(name, options) if object.respond_to?("errors") && object.errors.respond_to?("on") error_wrapping(tag_without_error_wrapping(name, options), object.errors.on(@method_name)) @@ -142,7 +141,6 @@ module ActionView end alias_method :content_tag_without_error_wrapping, :content_tag - def content_tag(name, value, options) if object.respond_to?("errors") && object.errors.respond_to?("on") error_wrapping(content_tag_without_error_wrapping(name, value, options), object.errors.on(@method_name)) diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 253b389a79..d9a1c7d55e 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -135,15 +135,15 @@ module ActionView html_options.merge!({ "size" => options["maxlength"]}) if options["maxlength"] && !options["size"] html_options.delete("size") if field_type == "hidden" html_options.merge!({ "type" => field_type}) - html_options.merge!({ "value" => value.to_s }) unless options["value"] + html_options.merge!({ "value" => value_before_type_cast }) unless options["value"] add_default_name_and_id(html_options) tag("input", html_options) end def to_radio_button_tag(tag_value, options={}) html_options = DEFAULT_FIELD_OPTIONS.merge(options) - html_options.merge!({"checked"=>"checked"}) if value == tag_value - html_options.merge!({"type"=>"radio", "value"=>tag_value.to_s}) + html_options.merge!({ "checked" => "checked" }) if value == tag_value + html_options.merge!({ "type" => "radio", "value"=> tag_value.to_s }) add_default_name_and_id(html_options) tag("input", html_options) @@ -152,11 +152,11 @@ module ActionView def to_text_area_tag(options = {}) options = DEFAULT_TEXT_AREA_OPTIONS.merge(options) add_default_name_and_id(options) - content_tag("textarea", html_escape(value), options) + content_tag("textarea", html_escape(value_before_type_cast), options) end def to_check_box_tag(options = {}, checked_value = "1", unchecked_value = "0") - options.merge!({"checked" => "checked"}) if !value.nil? && ((value.is_a?(TrueClass) || value.is_a?(FalseClass)) ? value : value.to_i > 0) + options.merge!({ "checked" => "checked" }) if !value.nil? && ((value.is_a?(TrueClass) || value.is_a?(FalseClass)) ? value : value.to_i > 0) options.merge!({ "type" => "checkbox", "value" => checked_value }) add_default_name_and_id(options) tag("input", options) << tag("input", ({ "name" => options['name'], "type" => "hidden", "value" => unchecked_value })) @@ -191,6 +191,10 @@ module ActionView object.send(@method_name) unless object.nil? end + def value_before_type_cast + object.send(@method_name + "_before_type_cast") unless object.nil? + end + private def add_default_name_and_id(options) options['name'] = tag_name unless options.has_key? "name" -- cgit v1.2.3