From 0f49caa6e0544521765fce2010337e3376e18c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Mon, 16 Jan 2012 21:49:55 -0300 Subject: Extract NumberField --- actionpack/lib/action_view/helpers/form_helper.rb | 2 +- actionpack/lib/action_view/helpers/tags.rb | 1 + .../lib/action_view/helpers/tags/number_field.rb | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 actionpack/lib/action_view/helpers/tags/number_field.rb (limited to 'actionpack/lib/action_view') 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 -- cgit v1.2.3