aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib
diff options
context:
space:
mode:
authorneumayr <neumayr@users.noreply.github.com>2017-11-09 17:37:06 +0100
committerneumayr <neumayr@users.noreply.github.com>2017-11-09 17:37:06 +0100
commitead4776b82f838ee0630770d1852e8b02ac0f923 (patch)
treecc6416978ff0091d726d978d0b1fb8477108cd60 /actionview/lib
parent0c2cb880e34c943275758ca6a6ff84afa7a29fba (diff)
downloadrails-ead4776b82f838ee0630770d1852e8b02ac0f923.tar.gz
rails-ead4776b82f838ee0630770d1852e8b02ac0f923.tar.bz2
rails-ead4776b82f838ee0630770d1852e8b02ac0f923.zip
Fix field_error_proc wrap form select optgroup and divider option tag
### Summary The [`:field_error_proc`](https://github.com/rails/rails/blob/master/actionview/lib/action_view/base.rb#L145) is responsible for decorating input tags that refer to attributes with errors. This default build-in rails feature wrap invalid form elements with additional markup: `<div class="field_with_errors">[…]</div>`. * Fix for `field_error_proc` wraps form select `optgroup` * Fix for `field_error_proc` wraps form select divider `option` * Add tests for uncovered elements with errors [Fixes #31088] #### Test coverage * `test_select_grouped_options_with_errors` * `test_time_zone_select_with_priority_zones_and_errors` #### Extend test coverage * `test_collection_select_with_errors` * `test_label_with_errors` * `test_check_box_with_errors` * `test_check_boxes_with_errors` * `test_radio_button_with_errors` * `test_radio_buttons_with_errors` * `test_collection_check_boxes_with_errors` * `test_collection_radio_buttons_with_errors`
Diffstat (limited to 'actionview/lib')
-rw-r--r--actionview/lib/action_view/helpers/active_model_helper.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/actionview/lib/action_view/helpers/active_model_helper.rb b/actionview/lib/action_view/helpers/active_model_helper.rb
index f1ef715710..e41a95d2ce 100644
--- a/actionview/lib/action_view/helpers/active_model_helper.rb
+++ b/actionview/lib/action_view/helpers/active_model_helper.rb
@@ -17,8 +17,8 @@ module ActionView
end
end
- def content_tag(*)
- error_wrapping(super)
+ def content_tag(type, options, *)
+ select_markup_helper?(type) ? super : error_wrapping(super)
end
def tag(type, options, *)
@@ -43,6 +43,10 @@ module ActionView
object.respond_to?(:errors) && object.errors.respond_to?(:[]) && error_message.present?
end
+ def select_markup_helper?(type)
+ ["optgroup", "option"].include?(type)
+ end
+
def tag_generate_errors?(options)
options["type"] != "hidden"
end