mirror of
https://github.com/heartcombo/simple_form.git
synced 2022-11-09 12:19:26 -05:00
Nested simple_form calls no longer lose reference to original error proc.
This commit is contained in:
parent
18306d8a77
commit
1db2571827
2 changed files with 21 additions and 6 deletions
|
@ -9,10 +9,6 @@ module SimpleForm
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
module FormHelper
|
module FormHelper
|
||||||
# based on what is done in formtastic
|
|
||||||
# http://github.com/justinfrench/formtastic/blob/master/lib/formtastic.rb#L1706
|
|
||||||
@@default_field_error_proc = nil
|
|
||||||
|
|
||||||
# Override the default ActiveRecordHelper behaviour of wrapping the input.
|
# Override the default ActiveRecordHelper behaviour of wrapping the input.
|
||||||
# This gets taken care of semantically by adding an error class to the wrapper tag
|
# This gets taken care of semantically by adding an error class to the wrapper tag
|
||||||
# containing the input.
|
# containing the input.
|
||||||
|
@ -46,10 +42,10 @@ module SimpleForm
|
||||||
private
|
private
|
||||||
|
|
||||||
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
|
||||||
::ActionView::Base.field_error_proc = FIELD_ERROR_PROC
|
::ActionView::Base.field_error_proc = FIELD_ERROR_PROC
|
||||||
result = yield
|
result = yield
|
||||||
::ActionView::Base.field_error_proc = @@default_field_error_proc
|
::ActionView::Base.field_error_proc = default_field_error_proc
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -101,4 +101,23 @@ class FormHelperTest < ActionView::TestCase
|
||||||
|
|
||||||
assert_select "input[name='author[name]'][value='hash backed author']"
|
assert_select "input[name='author[name]'][value='hash backed author']"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'custom error proc is not destructive' do
|
||||||
|
previous_error_proc = ActionView::Base.field_error_proc
|
||||||
|
|
||||||
|
begin
|
||||||
|
expected_error_proc = lambda {}
|
||||||
|
ActionView::Base.field_error_proc = expected_error_proc
|
||||||
|
|
||||||
|
simple_form_for :user do |f|
|
||||||
|
simple_fields_for 'address' do
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal expected_error_proc, ActionView::Base.field_error_proc
|
||||||
|
|
||||||
|
ensure
|
||||||
|
ActionView::Base.field_error_proc = previous_error_proc
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue