aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/form_tag_helper.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-12-30 19:41:25 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-12-30 19:41:25 +0000
commit00541f263b0aac16cdfcef68b4af5b1877f4dd02 (patch)
tree8969b86dcedf3f65ac9d50c5f2f9fdb4c086859c /actionpack/lib/action_view/helpers/form_tag_helper.rb
parent63c822afb22ea17cffd55a3d1c3472405e977be5 (diff)
downloadrails-00541f263b0aac16cdfcef68b4af5b1877f4dd02.tar.gz
rails-00541f263b0aac16cdfcef68b4af5b1877f4dd02.tar.bz2
rails-00541f263b0aac16cdfcef68b4af5b1877f4dd02.zip
Added :disable_with option to FormTagHelper#submit_tag to allow for easily disabled submit buttons with different text [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3361 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers/form_tag_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/form_tag_helper.rb40
1 files changed, 21 insertions, 19 deletions
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index f4f5382311..c7a5d1bb2d 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -17,14 +17,9 @@ module ActionView
# * <tt>:method</tt> - The method to use when submitting the form, usually either "get" or "post".
def form_tag(url_for_options = {}, options = {}, *parameters_for_url, &proc)
html_options = { "method" => "post" }.merge(options.stringify_keys)
-
- if html_options["multipart"]
- html_options["enctype"] = "multipart/form-data"
- html_options.delete("multipart")
- end
-
+ html_options["enctype"] = "multipart/form-data" if html_options.delete("multipart")
html_options["action"] = url_for(url_for_options, *parameters_for_url)
- tag("form", html_options, true)
+ tag :form, html_options, true
end
alias_method :start_form_tag, :form_tag
@@ -47,7 +42,7 @@ module ActionView
# Options:
# * <tt>:multiple</tt> - 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(options.stringify_keys))
+ content_tag :select, option_tags, { "name" => name, "id" => name }.update(options.stringify_keys)
end
# Creates a standard text field.
@@ -59,7 +54,7 @@ module ActionView
#
# 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(options.stringify_keys))
+ tag :input, { "type" => "text", "name" => name, "id" => name, "value" => value }.update(options.stringify_keys)
end
# Creates a hidden field.
@@ -97,39 +92,46 @@ module ActionView
# # Outputs <textarea name="body" id="body" cols="25" rows="10"></textarea>
# <%= text_area_tag "body", nil, :size => "25x10" %>
def text_area_tag(name, content = nil, options = {})
- options = options.stringify_keys
- if options["size"]
- options["cols"], options["rows"] = options["size"].split("x")
- options.delete("size")
+ options.stringify_keys!
+
+ if size = options.delete("size")
+ options["cols"], options["rows"] = size.split("x")
end
- content_tag("textarea", content, { "name" => name, "id" => name }.update(options.stringify_keys))
+ content_tag :textarea, content, { "name" => name, "id" => name }.update(options.stringify_keys)
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(options.stringify_keys)
html_options["checked"] = "checked" if checked
- tag("input", html_options)
+ 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(options.stringify_keys)
html_options["checked"] = "checked" if checked
- tag("input", html_options)
+ tag :input, html_options
end
- # Creates a submit button with the text <tt>value</tt> as the caption.
+ # Creates a submit button with the text <tt>value</tt> as the caption. If options contains a pair with the key of "disable_with",
+ # then the value will be used to rename a disabled version of the submit button.
def submit_tag(value = "Save changes", options = {})
- tag("input", { "type" => "submit", "name" => "commit", "value" => value }.update(options.stringify_keys))
+ options.stringify_keys!
+
+ if disable_with = options.delete("disable_with")
+ options["onclick"] = "this.disabled=true;this.value='#{disable_with}';this.form.submit();#{options["onclick"]}"
+ end
+
+ tag :input, { "type" => "submit", "name" => "commit", "value" => value }.update(options.stringify_keys)
end
# Displays an image which when clicked will submit the form.
#
# <tt>source</tt> is passed to AssetTagHelper#image_path
def image_submit_tag(source, options = {})
- tag("input", { "type" => "image", "src" => image_path(source) }.update(options.stringify_keys))
+ tag :input, { "type" => "image", "src" => image_path(source) }.update(options.stringify_keys)
end
end
end