diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2010-04-05 16:07:44 -0700 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2010-04-05 16:07:44 -0700 |
commit | f8730e5ce6bba4de7639ac09c6c193458038f748 (patch) | |
tree | 7b0609cc52a6eccc5d0461769bc134f78204b2e9 /actionpack/lib/action_view/helpers/form_tag_helper.rb | |
parent | 40a3e6739092bcfc568a5df645db0fd2783e8a22 (diff) | |
download | rails-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_tag_helper.rb')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_tag_helper.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 0d47c6eecb..10660ecec1 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -457,6 +457,69 @@ module ActionView output.safe_concat("</fieldset>") end + # Creates a text field of type "search". + # + # ==== Options + # * Accepts the same options as text_field_tag. + def search_field_tag(name, value = nil, options = {}) + text_field_tag(name, value, options.stringify_keys.update("type" => "search")) + end + + # Creates a text field of type "tel". + # + # ==== Options + # * Accepts the same options as text_field_tag. + def telephone_field_tag(name, value = nil, options = {}) + text_field_tag(name, value, options.stringify_keys.update("type" => "tel")) + end + alias phone_field_tag telephone_field_tag + + # Creates a text field of type "url". + # + # ==== Options + # * Accepts the same options as text_field_tag. + def url_field_tag(name, value = nil, options = {}) + text_field_tag(name, value, options.stringify_keys.update("type" => "url")) + end + + # Creates a text field of type "email". + # + # ==== Options + # * Accepts the same options as text_field_tag. + def email_field_tag(name, value = nil, options = {}) + text_field_tag(name, value, options.stringify_keys.update("type" => "email")) + end + + # Creates a number field. + # + # ==== Options + # * <tt>:min</tt> - The minimum acceptable value. + # * <tt>:max</tt> - The maximum acceptable value. + # * <tt>:in</tt> - A range specifying the <tt>:min</tt> and + # <tt>:max</tt> values. + # * <tt>:step</tt> - The acceptable value granularity. + # * Otherwise accepts the same options as text_field_tag. + # + # ==== Examples + # number_field_tag 'quantity', nil, :in => 1...10 + # => <input id="quantity" name="quantity" min="1" max="9" /> + def number_field_tag(name, value = nil, options = {}) + options = options.stringify_keys + options["type"] ||= "number" + if range = options.delete("in") || options.delete("within") + options.update("min" => range.min, "max" => range.max) + end + text_field_tag(name, value, options) + end + + # Creates a range form element. + # + # ==== Options + # * Accepts the same options as number_field_tag. + def range_field_tag(name, value = nil, options = {}) + number_field_tag(name, value, options.stringify_keys.update("type" => "range")) + end + private def html_options_for_form(url_for_options, options, *parameters_for_url) returning options.stringify_keys do |html_options| |