aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-01-16 21:49:55 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-01-17 00:05:30 -0300
commit0f49caa6e0544521765fce2010337e3376e18c83 (patch)
treec1406eaa63af9faa19cc9cf711c8825d27c8cdfe /actionpack/lib/action_view
parent647aff9e51dca62ea793c68c5ff830c8b364aa50 (diff)
downloadrails-0f49caa6e0544521765fce2010337e3376e18c83.tar.gz
rails-0f49caa6e0544521765fce2010337e3376e18c83.tar.bz2
rails-0f49caa6e0544521765fce2010337e3376e18c83.zip
Extract NumberField
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb2
-rw-r--r--actionpack/lib/action_view/helpers/tags.rb1
-rw-r--r--actionpack/lib/action_view/helpers/tags/number_field.rb19
3 files changed, 21 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index ab957597cd..8d0375bf4f 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -912,7 +912,7 @@ module ActionView
# ==== 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".
diff --git a/actionpack/lib/action_view/helpers/tags.rb b/actionpack/lib/action_view/helpers/tags.rb
index eb48625f80..6071ce1913 100644
--- a/actionpack/lib/action_view/helpers/tags.rb
+++ b/actionpack/lib/action_view/helpers/tags.rb
@@ -11,6 +11,7 @@ module ActionView
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'
diff --git a/actionpack/lib/action_view/helpers/tags/number_field.rb b/actionpack/lib/action_view/helpers/tags/number_field.rb
new file mode 100644
index 0000000000..e89fdbec46
--- /dev/null
+++ b/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