Refactor has errors in both error component and error notification
This commit is contained in:
parent
a02f805ddf
commit
27ba278b6c
|
@ -6,6 +6,7 @@ module SimpleForm
|
|||
autoload :Components, 'simple_form/components'
|
||||
autoload :ErrorNotification, 'simple_form/error_notification'
|
||||
autoload :FormBuilder, 'simple_form/form_builder'
|
||||
autoload :HasErrors, 'simple_form/has_errors'
|
||||
autoload :I18nCache, 'simple_form/i18n_cache'
|
||||
autoload :Inputs, 'simple_form/inputs'
|
||||
autoload :MapType, 'simple_form/map_type'
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
module SimpleForm
|
||||
module Components
|
||||
module Errors
|
||||
include SimpleForm::HasErrors
|
||||
|
||||
def error
|
||||
template.content_tag(error_tag, error_text, error_html_options) if has_errors?
|
||||
end
|
||||
|
@ -23,10 +25,6 @@ module SimpleForm
|
|||
|
||||
protected
|
||||
|
||||
def has_errors?
|
||||
object && object.respond_to?(:errors) && errors.present?
|
||||
end
|
||||
|
||||
def errors
|
||||
@errors ||= (errors_on_attribute + errors_on_association).compact
|
||||
end
|
||||
|
@ -40,4 +38,4 @@ module SimpleForm
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
module SimpleForm
|
||||
class ErrorNotification
|
||||
delegate :object, :object_name, :template, :to => :@builder
|
||||
include SimpleForm::HasErrors
|
||||
|
||||
def initialize(builder, options)
|
||||
@builder = builder
|
||||
|
@ -24,10 +25,6 @@ module SimpleForm
|
|||
SimpleForm.error_notification_tag
|
||||
end
|
||||
|
||||
def has_errors?
|
||||
object && object.respond_to?(:errors) && object.errors.present?
|
||||
end
|
||||
|
||||
def html_options
|
||||
@options[:class] = "error_notification #{@options[:class]}".strip
|
||||
@options
|
||||
|
@ -41,4 +38,4 @@ module SimpleForm
|
|||
I18n.t(lookups.shift, :scope => :"simple_form.error_notification", :default => lookups)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
module SimpleForm
|
||||
module HasErrors
|
||||
|
||||
protected
|
||||
|
||||
def errors
|
||||
object.errors
|
||||
end
|
||||
|
||||
def has_errors?
|
||||
object && object.respond_to?(:errors) && errors.present?
|
||||
end
|
||||
end
|
||||
end
|
|
@ -11,9 +11,7 @@ module SimpleForm
|
|||
input_options[:size] ||= SimpleForm.default_input_size
|
||||
input_options[:step] ||= 1 if integer?
|
||||
input_options[:placeholder] ||= placeholder if has_placeholder?
|
||||
|
||||
infer_attributes_from_validations(input_options)
|
||||
|
||||
input_options
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue