From ecb0e3974123c7dfc503311f014f30fa1b77943b Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 22 Jul 2005 06:47:03 +0000 Subject: Added additional documentation to FormTagHelper #1788 [jon@instance-design.co.uk] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1880 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/action_view/helpers/form_tag_helper.rb | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'actionpack/lib/action_view/helpers/form_tag_helper.rb') diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index ed8c1c1d3e..573b753346 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -14,6 +14,7 @@ module ActionView # # Options: # * :multipart - If set to true, the enctype is set to "multipart/form-data". + # * :method - The method to use when submitting the form, usually either "get" or "post". def form_tag(url_for_options = {}, options = {}, *parameters_for_url) html_options = { "method" => "post" }.merge(options.stringify_keys) @@ -33,26 +34,68 @@ module ActionView "" end + # Creates a dropdown selection box, or if the :multiple option is set to true, a multiple + # choice selection box. + # + # Helpers::FormOptions can be used to create common select boxes such as countries, time zones, or + # associated records. + # + # option_tags is a string containing the option tags for the select box: + # # Outputs + # select_tag "people", "" + # + # Options: + # * :multiple - If set to true the selection will allow multiple choices. def select_tag(name, option_tags = nil, options = {}) content_tag("select", option_tags, { "name" => name, "id" => name }.update(convert_options(options))) end + # Creates a standard text field. + # + # Options: + # * :disabled - If set to true, the user will not be able to use this input. + # * :size - The number of visible characters that will fit in the input. + # * :maxlength - The maximum number of characters that the browser will allow the user to enter. + # + # A hash of standard HTML options for the tag. def text_field_tag(name, value = nil, options = {}) tag("input", { "type" => "text", "name" => name, "id" => name, "value" => value }.update(convert_options(options))) end + # Creates a hidden field. + # + # Takes the same options as text_field_tag def hidden_field_tag(name, value = nil, options = {}) text_field_tag(name, value, options.stringify_keys.update("type" => "hidden")) end + # Creates a file upload field. + # + # If you are using file uploads then you will also need to set the multipart option for the form: + # <%= form_tag { :action => "post" }, { :multipart => true } %> + # <%= file_field_tag "file" %> + # <%= submit_tag %> + # <%= end_form_tag %> + # + # The specified URL will then be passed a File object containing the selected file, or if the field + # was left blank, a StringIO object. def file_field_tag(name, options = {}) text_field_tag(name, nil, convert_options(options).update("type" => "file")) end + # Creates a password field. + # + # Takes the same options as text_field_tag def password_field_tag(name = "password", value = nil, options = {}) text_field_tag(name, value, convert_options(options).update("type" => "password")) end + # Creates a text input area. + # + # Options: + # * :size - A string specifying the dimensions of the textarea. + # # Outputs + # <%= text_area_tag "body", nil, :size => 25x10 %> def text_area_tag(name, content = nil, options = {}) options = options.stringify_keys if options["size"] @@ -63,22 +106,28 @@ module ActionView content_tag("textarea", content, { "name" => name, "id" => name }.update(convert_options(options))) end + # Creates a check box. def check_box_tag(name, value = "1", checked = false, options = {}) html_options = { "type" => "checkbox", "name" => name, "id" => name, "value" => value }.update(convert_options(options)) html_options["checked"] = "checked" if checked tag("input", html_options) end + # Creates a radio button. def radio_button_tag(name, value, checked = false, options = {}) html_options = { "type" => "radio", "name" => name, "id" => name, "value" => value }.update(convert_options(options)) html_options["checked"] = "checked" if checked tag("input", html_options) end + # Creates a submit button with the text value as the caption. def submit_tag(value = "Save changes", options = {}) tag("input", { "type" => "submit", "name" => "commit", "value" => value }.update(convert_options(options))) end + # Displays an image which when clicked will submit the form. + # + # source is passed to AssetTagHelper#image_path def image_submit_tag(source, options = {}) tag("input", { "type" => "image", "src" => image_path(source) }.update(convert_options(options))) end -- cgit v1.2.3