Skip to content
Browse files

Extract NumberField

  • Loading branch information...
1 parent 647aff9 commit 0f49caa6e0544521765fce2010337e3376e18c83 @rafaelfranca rafaelfranca committed
View
2 actionpack/lib/action_view/helpers/form_helper.rb
@@ -912,7 +912,7 @@ def email_field(object_name, method, options = {})
# ==== Options
# * Accepts same options as number_field_tag
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
# Returns an input tag of type "range".
View
1 actionpack/lib/action_view/helpers/tags.rb
@@ -11,6 +11,7 @@ module Tags
autoload :TelField, 'action_view/helpers/tags/tel_field'
autoload :UrlField, 'action_view/helpers/tags/url_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 :CheckBox, 'action_view/helpers/tags/check_box'
autoload :RadioButton, 'action_view/helpers/tags/radio_button'
View
19 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.
Something went wrong with that request. Please try again.