mirror of
https://github.com/heartcombo/simple_form.git
synced 2022-11-09 12:19:26 -05:00
Small cleanup on implementation.
This commit is contained in:
parent
50b24b5cbe
commit
05cf7a24df
2 changed files with 11 additions and 14 deletions
|
@ -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?
|
||||
|
|
|
@ -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?
|
||||
|
|
Loading…
Reference in a new issue