-
Notifications
You must be signed in to change notification settings - Fork 630
/
range_input.rb
33 lines (30 loc) · 1.31 KB
/
range_input.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module Formtastic
module Inputs
module RangeInput
include Formtastic::Inputs::Base
def range_input(method, options)
reflections = @object.class.reflect_on_validations_for(method) if @object.class.respond_to?(:reflect_on_validations_for)
reflections.each do |reflection|
if reflection.macro == :validates_numericality_of
unless options.include? :in
if reflection.options.include?(:greater_than)
range_start = (reflection.options[:greater_than] + 1)
elsif reflection.options.include?(:greater_than_or_equal_to)
range_start = reflection.options[:greater_than_or_equal_to]
end
if reflection.options.include?(:less_than)
range_end = (reflection.options[:less_than] - 1)
elsif reflection.options.include?(:less_than_or_equal_to)
range_end = reflection.options[:less_than_or_equal_to]
end
end
options[:input_html] ||= {}
options[:input_html][:in] = options.delete(:in) || (range_start..range_end)
options[:input_html][:step] = options.delete(:step) || 1
end
end
basic_input_helper(:range_field, :numeric, method, options)
end
end
end
end