mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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
This commit is contained in:
parent
63c822afb2
commit
00541f263b
3 changed files with 30 additions and 19 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Added :disable_with option to FormTagHelper#submit_tag to allow for easily disabled submit buttons with different text [DHH]
|
||||
|
||||
* Make auto_link handle nil by returning quickly if blank? [Scott Barron]
|
||||
|
||||
* Make auto_link match urls with a port number specified. [Marcel Molina Jr.]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -94,6 +94,13 @@ class FormTagHelperTest < Test::Unit::TestCase
|
|||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
||||
def test_submit_tag
|
||||
assert_dom_equal(
|
||||
%(<input name='commit' type='submit' value='Save' onclick="this.disabled=true;this.value='Saving...';this.form.submit();alert('hello!')" />),
|
||||
submit_tag("Save", :disable_with => "Saving...", :onclick => "alert('hello!')")
|
||||
)
|
||||
end
|
||||
|
||||
def test_pass
|
||||
assert_equal 1, 1
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue