diff --git a/lib/simple_form.rb b/lib/simple_form.rb index 0f89e983..d559c174 100644 --- a/lib/simple_form.rb +++ b/lib/simple_form.rb @@ -139,6 +139,14 @@ module SimpleForm mattr_accessor :button_class @@button_class = 'button' + # Override the default ActiveModelHelper behaviour of wrapping the input. + # This gets taken care of semantically by adding an error class to the wrapper tag + # containing the input. + mattr_accessor :field_error_proc + @@field_error_proc = proc do |html_tag, instance_tag| + html_tag + end + ## WRAPPER CONFIGURATION # The default wrapper to be used by the FormBuilder. mattr_accessor :default_wrapper diff --git a/lib/simple_form/action_view_extensions/form_helper.rb b/lib/simple_form/action_view_extensions/form_helper.rb index 309ab0b0..1a2d3017 100644 --- a/lib/simple_form/action_view_extensions/form_helper.rb +++ b/lib/simple_form/action_view_extensions/form_helper.rb @@ -9,13 +9,6 @@ module SimpleForm # end # module FormHelper - # Override the default ActiveRecordHelper behaviour of wrapping the input. - # This gets taken care of semantically by adding an error class to the wrapper tag - # containing the input. - # - FIELD_ERROR_PROC = proc do |html_tag, instance_tag| - html_tag - end def simple_form_for(record, options={}, &block) options[:builder] ||= SimpleForm::FormBuilder @@ -44,7 +37,7 @@ module SimpleForm def with_simple_form_field_error_proc default_field_error_proc = ::ActionView::Base.field_error_proc begin - ::ActionView::Base.field_error_proc = FIELD_ERROR_PROC + ::ActionView::Base.field_error_proc = SimpleForm.field_error_proc yield ensure ::ActionView::Base.field_error_proc = default_field_error_proc diff --git a/test/action_view_extensions/form_helper_test.rb b/test/action_view_extensions/form_helper_test.rb index c9604d14..e9964aff 100644 --- a/test/action_view_extensions/form_helper_test.rb +++ b/test/action_view_extensions/form_helper_test.rb @@ -131,6 +131,15 @@ class FormHelperTest < ActionView::TestCase end end + test 'SimpleForm for swaps default action view field_error_proc' do + expected_error_proc = lambda {} + swap SimpleForm, field_error_proc: expected_error_proc do + simple_form_for :user do |f| + assert_equal expected_error_proc, ::ActionView::Base.field_error_proc + end + end + end + private def swap_field_error_proc(expected_error_proc = lambda {})