diff --git a/lib/simple_form/inputs/numeric_input.rb b/lib/simple_form/inputs/numeric_input.rb index 320793c9..0b6f3f0f 100644 --- a/lib/simple_form/inputs/numeric_input.rb +++ b/lib/simple_form/inputs/numeric_input.rb @@ -5,6 +5,7 @@ module SimpleForm def input add_size! + input_html_classes.unshift("numeric") if SimpleForm.html5 input_html_options[:type] ||= "number" input_html_options[:step] ||= integer? ? 1 : "any" @@ -13,10 +14,6 @@ module SimpleForm @builder.text_field(attribute_name, input_html_options) end - def input_html_classes - super.unshift("numeric") - end - private # Rails adds the size attr by default, if the :size key does not exist. @@ -27,11 +24,11 @@ module SimpleForm def infer_attributes_from_validations! return unless has_validators? - numeric_validator = find_numericality_validator or return - validator_options = numeric_validator.options - - input_html_options[:min] ||= minimum_value(validator_options) - input_html_options[:max] ||= maximum_value(validator_options) + if numeric_validator = find_numericality_validator + validator_options = numeric_validator.options + input_html_options[:min] ||= minimum_value(validator_options) + input_html_options[:max] ||= maximum_value(validator_options) + end end def integer? diff --git a/lib/simple_form/inputs/string_input.rb b/lib/simple_form/inputs/string_input.rb index 1d1f9bf1..1e442e83 100644 --- a/lib/simple_form/inputs/string_input.rb +++ b/lib/simple_form/inputs/string_input.rb @@ -4,15 +4,15 @@ module SimpleForm enable :placeholder, :maxlength, :pattern def input - input_html_options[:type] ||= input_type if SimpleForm.html5 && !string? + unless string? + input_html_classes.unshift("string") + input_html_options[:type] ||= input_type if SimpleForm.html5 + end + add_size! @builder.text_field(attribute_name, input_html_options) end - def input_html_classes - string? ? super : super.unshift("string") - end - private def string?