mirror of
https://github.com/heartcombo/simple_form.git
synced 2022-11-09 12:19:26 -05:00
override ActionView::Base.field_error_proc since the error class is now on the wrapper
This commit is contained in:
parent
8cb2092c40
commit
a7de18f9b7
1 changed files with 24 additions and 1 deletions
|
@ -10,6 +10,26 @@ 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.
|
||||||
|
# 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 with_custom_field_error_proc(&block)
|
||||||
|
@@default_field_error_proc = ::ActionView::Base.field_error_proc
|
||||||
|
::ActionView::Base.field_error_proc = FIELD_ERROR_PROC
|
||||||
|
result = yield
|
||||||
|
::ActionView::Base.field_error_proc = @@default_field_error_proc
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
[:form_for, :fields_for, :remote_form_for].each do |helper|
|
[:form_for, :fields_for, :remote_form_for].each do |helper|
|
||||||
class_eval <<-METHOD, __FILE__, __LINE__
|
class_eval <<-METHOD, __FILE__, __LINE__
|
||||||
def simple_#{helper}(record_or_name_or_array, *args, &block)
|
def simple_#{helper}(record_or_name_or_array, *args, &block)
|
||||||
|
@ -22,8 +42,11 @@ module SimpleForm
|
||||||
end
|
end
|
||||||
options[:html] ||= {}
|
options[:html] ||= {}
|
||||||
options[:html][:class] = "simple_form \#{css_class} \#{options[:html][:class]}".strip
|
options[:html][:class] = "simple_form \#{css_class} \#{options[:html][:class]}".strip
|
||||||
|
|
||||||
|
with_custom_field_error_proc do
|
||||||
#{helper}(record_or_name_or_array, *(args << options), &block)
|
#{helper}(record_or_name_or_array, *(args << options), &block)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
METHOD
|
METHOD
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue