2010-02-06 16:21:26 -05:00
|
|
|
module SimpleForm
|
|
|
|
module Inputs
|
|
|
|
class NumericInput < Base
|
2011-12-04 10:31:13 -05:00
|
|
|
enable :placeholder, :min_max
|
2011-12-04 07:29:59 -05:00
|
|
|
|
2010-02-06 16:21:26 -05:00
|
|
|
def input
|
2011-09-03 09:33:04 -04:00
|
|
|
add_size!
|
2011-12-04 09:56:05 -05:00
|
|
|
input_html_classes.unshift("numeric")
|
2011-12-04 10:15:27 -05:00
|
|
|
if html5?
|
2011-09-03 09:08:51 -04:00
|
|
|
input_html_options[:type] ||= "number"
|
|
|
|
input_html_options[:step] ||= integer? ? 1 : "any"
|
|
|
|
end
|
2010-02-06 16:21:26 -05:00
|
|
|
@builder.text_field(attribute_name, input_html_options)
|
|
|
|
end
|
|
|
|
|
2011-09-03 05:13:29 -04:00
|
|
|
private
|
2010-11-07 04:41:33 -05:00
|
|
|
|
2011-09-03 09:33:04 -04:00
|
|
|
# Rails adds the size attr by default, if the :size key does not exist.
|
|
|
|
def add_size!
|
|
|
|
input_html_options[:size] ||= nil
|
|
|
|
end
|
2010-02-06 16:21:26 -05:00
|
|
|
end
|
|
|
|
end
|
2010-09-05 11:19:45 -04:00
|
|
|
end
|