Merge pull request #773 from dfens/master
Make FIELD_ERROR_PROC configurable
This commit is contained in:
commit
8a00b01d49
|
@ -139,6 +139,14 @@ module SimpleForm
|
||||||
mattr_accessor :button_class
|
mattr_accessor :button_class
|
||||||
@@button_class = 'button'
|
@@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
|
## WRAPPER CONFIGURATION
|
||||||
# The default wrapper to be used by the FormBuilder.
|
# The default wrapper to be used by the FormBuilder.
|
||||||
mattr_accessor :default_wrapper
|
mattr_accessor :default_wrapper
|
||||||
|
|
|
@ -9,13 +9,6 @@ module SimpleForm
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
module FormHelper
|
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)
|
def simple_form_for(record, options={}, &block)
|
||||||
options[:builder] ||= SimpleForm::FormBuilder
|
options[:builder] ||= SimpleForm::FormBuilder
|
||||||
|
@ -44,7 +37,7 @@ module SimpleForm
|
||||||
def with_simple_form_field_error_proc
|
def with_simple_form_field_error_proc
|
||||||
default_field_error_proc = ::ActionView::Base.field_error_proc
|
default_field_error_proc = ::ActionView::Base.field_error_proc
|
||||||
begin
|
begin
|
||||||
::ActionView::Base.field_error_proc = FIELD_ERROR_PROC
|
::ActionView::Base.field_error_proc = SimpleForm.field_error_proc
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
::ActionView::Base.field_error_proc = default_field_error_proc
|
::ActionView::Base.field_error_proc = default_field_error_proc
|
||||||
|
|
|
@ -131,6 +131,15 @@ class FormHelperTest < ActionView::TestCase
|
||||||
end
|
end
|
||||||
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
|
private
|
||||||
|
|
||||||
def swap_field_error_proc(expected_error_proc = lambda {})
|
def swap_field_error_proc(expected_error_proc = lambda {})
|
||||||
|
|
Loading…
Reference in New Issue