Skip to content

Commit

Permalink
Extract NumberField
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Jan 17, 2012
1 parent 647aff9 commit 0f49caa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/form_helper.rb
Expand Up @@ -912,7 +912,7 @@ def email_field(object_name, method, options = {})
# ==== Options # ==== Options
# * Accepts same options as number_field_tag # * Accepts same options as number_field_tag
def number_field(object_name, method, options = {}) def number_field(object_name, method, options = {})
InstanceTag.new(object_name, method, self, options.delete(:object)).to_number_field_tag("number", options) ActionView::Helpers::Tags::NumberField.new(object_name, method, self, options).render
end end


# Returns an input tag of type "range". # Returns an input tag of type "range".
Expand Down
1 change: 1 addition & 0 deletions actionpack/lib/action_view/helpers/tags.rb
Expand Up @@ -11,6 +11,7 @@ module Tags
autoload :TelField, 'action_view/helpers/tags/tel_field' autoload :TelField, 'action_view/helpers/tags/tel_field'
autoload :UrlField, 'action_view/helpers/tags/url_field' autoload :UrlField, 'action_view/helpers/tags/url_field'
autoload :EmailField, 'action_view/helpers/tags/email_field' autoload :EmailField, 'action_view/helpers/tags/email_field'
autoload :NumberField, 'action_view/helpers/tags/number_field'
autoload :TextArea, 'action_view/helpers/tags/text_area' autoload :TextArea, 'action_view/helpers/tags/text_area'
autoload :CheckBox, 'action_view/helpers/tags/check_box' autoload :CheckBox, 'action_view/helpers/tags/check_box'
autoload :RadioButton, 'action_view/helpers/tags/radio_button' autoload :RadioButton, 'action_view/helpers/tags/radio_button'
Expand Down
19 changes: 19 additions & 0 deletions actionpack/lib/action_view/helpers/tags/number_field.rb
@@ -0,0 +1,19 @@
module ActionView
module Helpers
module Tags
class NumberField < TextField #:nodoc:
def render
options = @options.stringify_keys
options['size'] ||= nil

if range = options.delete("in") || options.delete("within")
options.update("min" => range.min, "max" => range.max)
end

@options = options
super
end
end
end
end
end

0 comments on commit 0f49caa

Please sign in to comment.