diff --git a/lib/simple_form/components/errors.rb b/lib/simple_form/components/errors.rb index 834a30a2..7f35db6f 100644 --- a/lib/simple_form/components/errors.rb +++ b/lib/simple_form/components/errors.rb @@ -1,8 +1,6 @@ module SimpleForm module Components module Errors - include SimpleForm::Helpers::HasErrors - def error enabled_error end @@ -17,6 +15,10 @@ module SimpleForm nil end + def has_errors? + object && object.respond_to?(:errors) && errors.present? + end + def error_text if options[:error_prefix] options[:error_prefix] + " " + errors.send(error_method) diff --git a/lib/simple_form/error_notification.rb b/lib/simple_form/error_notification.rb index 154bbf6a..580a9dbc 100644 --- a/lib/simple_form/error_notification.rb +++ b/lib/simple_form/error_notification.rb @@ -1,7 +1,6 @@ module SimpleForm class ErrorNotification delegate :object, :object_name, :template, :to => :@builder - include SimpleForm::Helpers::HasErrors def initialize(builder, options) @builder = builder @@ -17,6 +16,14 @@ module SimpleForm protected + def errors + object.errors + end + + def has_errors? + object && object.respond_to?(:errors) && errors.present? + end + def error_message @message || translate_error_notification end diff --git a/lib/simple_form/helpers.rb b/lib/simple_form/helpers.rb index 53bbc91e..9c98380a 100644 --- a/lib/simple_form/helpers.rb +++ b/lib/simple_form/helpers.rb @@ -1,6 +1,5 @@ module SimpleForm module Helpers - autoload :HasErrors, 'simple_form/helpers/has_errors' autoload :Maxlength, 'simple_form/helpers/maxlength' autoload :Pattern, 'simple_form/helpers/pattern' autoload :Validators, 'simple_form/helpers/validators' diff --git a/lib/simple_form/helpers/has_errors.rb b/lib/simple_form/helpers/has_errors.rb deleted file mode 100644 index 6a21a66f..00000000 --- a/lib/simple_form/helpers/has_errors.rb +++ /dev/null @@ -1,14 +0,0 @@ -module SimpleForm - module Helpers - module HasErrors - - def errors - object.errors - end - - def has_errors? - object && object.respond_to?(:errors) && errors.present? - end - end - end -end diff --git a/lib/simple_form/helpers/required.rb b/lib/simple_form/helpers/required.rb index 3094f914..cc56eba7 100644 --- a/lib/simple_form/helpers/required.rb +++ b/lib/simple_form/helpers/required.rb @@ -1,6 +1,11 @@ module SimpleForm module Helpers module Required + # Whether this input is valid for HTML 5 required attribute. + def has_required? + attribute_required? && SimpleForm.html5 && SimpleForm.browser_validations + end + private def attribute_required? @@ -19,11 +24,6 @@ module SimpleForm end end - # Whether this input is valid for HTML 5 required attribute. - def has_required? - attribute_required? && SimpleForm.html5 && SimpleForm.browser_validations - end - def attribute_required_by_default? SimpleForm.required_by_default end diff --git a/lib/simple_form/helpers/validators.rb b/lib/simple_form/helpers/validators.rb index 3cee158c..f2d0fd11 100644 --- a/lib/simple_form/helpers/validators.rb +++ b/lib/simple_form/helpers/validators.rb @@ -1,12 +1,12 @@ module SimpleForm module Helpers module Validators - private - def has_validators? attribute_name && object.class.respond_to?(:validators_on) end + private + def attribute_validators object.class.validators_on(attribute_name) end diff --git a/lib/simple_form/inputs/base.rb b/lib/simple_form/inputs/base.rb index 6facb76c..f4eea910 100644 --- a/lib/simple_form/inputs/base.rb +++ b/lib/simple_form/inputs/base.rb @@ -64,19 +64,10 @@ module SimpleForm options[:disabled] == true end - # Whether this input is valid for HTML 5 required attribute. - def has_required? - attribute_required? && SimpleForm.html5 && SimpleForm.browser_validations - end - def has_autofocus? options[:autofocus] end - def has_validators? - attribute_name && object.class.respond_to?(:validators_on) - end - private def add_size! @@ -87,10 +78,6 @@ module SimpleForm column && column.limit end - def has_autofocus? - options[:autofocus] - end - # Find reflection name when available, otherwise use attribute def reflection_or_attribute_name reflection ? reflection.name : attribute_name