aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/form_helper.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2010-04-05 16:07:44 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2010-04-05 16:07:44 -0700
commitf8730e5ce6bba4de7639ac09c6c193458038f748 (patch)
tree7b0609cc52a6eccc5d0461769bc134f78204b2e9 /actionpack/lib/action_view/helpers/form_helper.rb
parent40a3e6739092bcfc568a5df645db0fd2783e8a22 (diff)
downloadrails-f8730e5ce6bba4de7639ac09c6c193458038f748.tar.gz
rails-f8730e5ce6bba4de7639ac09c6c193458038f748.tar.bz2
rails-f8730e5ce6bba4de7639ac09c6c193458038f748.zip
Added all the new HTML5 form types as individual form tag methods (search, url, number, etc) (Closes #3646) [Stephen Celis]
Diffstat (limited to 'actionpack/lib/action_view/helpers/form_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 45f41edcac..932711f9de 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -784,6 +784,56 @@ module ActionView
def radio_button(object_name, method, tag_value, options = {})
InstanceTag.new(object_name, method, self, options.delete(:object)).to_radio_button_tag(tag_value, options)
end
+
+ # Returns a text_field of type "search".
+ def search_field(object_name, method, options = {})
+ options = options.stringify_keys
+
+ if options["autosave"]
+ if options["autosave"] == true
+ options["autosave"] = request.host.split(".").reverse.join(".")
+ end
+ options["results"] ||= 10
+ end
+
+ if options["onsearch"]
+ options["incremental"] = true unless options.has_key?("incremental")
+ end
+
+ InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("search", options)
+ end
+
+ # Returns a text_field of type "tel".
+ def telephone_field(object_name, method, options = {})
+ InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("tel", options)
+ end
+ alias phone_field telephone_field
+
+ # Returns a text_field of type "url".
+ def url_field(object_name, method, options = {})
+ InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("url", options)
+ end
+
+ # Returns a text_field of type "email".
+ def email_field(object_name, method, options = {})
+ InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("email", options)
+ end
+
+ # Returns an input tag of type "number".
+ #
+ # ==== 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)
+ end
+
+ # Returns an input tag of type "range".
+ #
+ # ==== Options
+ # * Accepts same options as range_field_tag
+ def range_field(object_name, method, options = {})
+ InstanceTag.new(object_name, method, self, options.delete(:object)).to_number_field_tag("range", options)
+ end
end
module InstanceTagMethods #:nodoc:
@@ -847,6 +897,14 @@ module ActionView
tag("input", options)
end
+ def to_number_field_tag(field_type, options = {})
+ options = options.stringify_keys
+ if range = options.delete("in") || options.delete("within")
+ options.update("min" => range.min, "max" => range.max)
+ end
+ to_input_field_tag(field_type, options)
+ end
+
def to_radio_button_tag(tag_value, options = {})
options = DEFAULT_RADIO_OPTIONS.merge(options.stringify_keys)
options["type"] = "radio"