diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2010-06-24 17:36:54 -0300 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-06-25 09:49:29 +0200 |
commit | b01df28413be0add0876de6406be9c02d4b96f4c (patch) | |
tree | 53822d96e29104606bfe7edf4b177f1cbe8e357e /actionpack/lib/action_view/helpers/active_model_helper.rb | |
parent | 617e94658ddc3f71c42fc4f8c2346f87ff106bbe (diff) | |
download | rails-b01df28413be0add0876de6406be9c02d4b96f4c.tar.gz rails-b01df28413be0add0876de6406be9c02d4b96f4c.tar.bz2 rails-b01df28413be0add0876de6406be9c02d4b96f4c.zip |
Do not wrap hidden fields with error proc [#4962 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack/lib/action_view/helpers/active_model_helper.rb')
-rw-r--r-- | actionpack/lib/action_view/helpers/active_model_helper.rb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/helpers/active_model_helper.rb b/actionpack/lib/action_view/helpers/active_model_helper.rb index 0f9b04cb5f..6bb0875bc3 100644 --- a/actionpack/lib/action_view/helpers/active_model_helper.rb +++ b/actionpack/lib/action_view/helpers/active_model_helper.rb @@ -36,12 +36,16 @@ module ActionView end end - %w(tag content_tag to_date_select_tag to_datetime_select_tag to_time_select_tag).each do |meth| + %w(content_tag to_date_select_tag to_datetime_select_tag to_time_select_tag).each do |meth| module_eval "def #{meth}(*) error_wrapping(super) end", __FILE__, __LINE__ end + def tag(type, options, *) + tag_generate_errors?(options) ? error_wrapping(super) : super + end + def error_wrapping(html_tag) - if object.respond_to?(:errors) && object.errors.respond_to?(:full_messages) && object.errors[@method_name].any? + if object_has_errors? Base.field_error_proc.call(html_tag, self) else html_tag @@ -51,6 +55,16 @@ module ActionView def error_message object.errors[@method_name] end + + private + + def object_has_errors? + object.respond_to?(:errors) && object.errors.respond_to?(:full_messages) && error_message.any? + end + + def tag_generate_errors?(options) + options['type'] != 'hidden' + end end class FormBuilder |