Skip to content

Commit

Permalink
Prettier code for RangeInput, allow for :step option.
Browse files Browse the repository at this point in the history
  • Loading branch information
farnoy committed Jan 31, 2011
1 parent b3938c8 commit 003009c
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions lib/formtastic/inputs/range_input.rb
Expand Up @@ -7,21 +7,24 @@ 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
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]
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) if options[:in]
options[:input_html][:in] ||= (range_start..range_end)
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

Expand Down

0 comments on commit 003009c

Please sign in to comment.