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*
|
*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 handle nil by returning quickly if blank? [Scott Barron]
|
||||||
|
|
||||||
* Make auto_link match urls with a port number specified. [Marcel Molina Jr.]
|
* 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".
|
# * <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)
|
def form_tag(url_for_options = {}, options = {}, *parameters_for_url, &proc)
|
||||||
html_options = { "method" => "post" }.merge(options.stringify_keys)
|
html_options = { "method" => "post" }.merge(options.stringify_keys)
|
||||||
|
html_options["enctype"] = "multipart/form-data" if html_options.delete("multipart")
|
||||||
if html_options["multipart"]
|
|
||||||
html_options["enctype"] = "multipart/form-data"
|
|
||||||
html_options.delete("multipart")
|
|
||||||
end
|
|
||||||
|
|
||||||
html_options["action"] = url_for(url_for_options, *parameters_for_url)
|
html_options["action"] = url_for(url_for_options, *parameters_for_url)
|
||||||
tag("form", html_options, true)
|
tag :form, html_options, true
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method :start_form_tag, :form_tag
|
alias_method :start_form_tag, :form_tag
|
||||||
|
@ -47,7 +42,7 @@ module ActionView
|
||||||
# Options:
|
# Options:
|
||||||
# * <tt>:multiple</tt> - If set to true the selection will allow multiple choices.
|
# * <tt>:multiple</tt> - If set to true the selection will allow multiple choices.
|
||||||
def select_tag(name, option_tags = nil, options = {})
|
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
|
end
|
||||||
|
|
||||||
# Creates a standard text field.
|
# Creates a standard text field.
|
||||||
|
@ -59,7 +54,7 @@ module ActionView
|
||||||
#
|
#
|
||||||
# A hash of standard HTML options for the tag.
|
# A hash of standard HTML options for the tag.
|
||||||
def text_field_tag(name, value = nil, options = {})
|
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
|
end
|
||||||
|
|
||||||
# Creates a hidden field.
|
# Creates a hidden field.
|
||||||
|
@ -97,39 +92,46 @@ module ActionView
|
||||||
# # Outputs <textarea name="body" id="body" cols="25" rows="10"></textarea>
|
# # Outputs <textarea name="body" id="body" cols="25" rows="10"></textarea>
|
||||||
# <%= text_area_tag "body", nil, :size => "25x10" %>
|
# <%= text_area_tag "body", nil, :size => "25x10" %>
|
||||||
def text_area_tag(name, content = nil, options = {})
|
def text_area_tag(name, content = nil, options = {})
|
||||||
options = options.stringify_keys
|
options.stringify_keys!
|
||||||
if options["size"]
|
|
||||||
options["cols"], options["rows"] = options["size"].split("x")
|
if size = options.delete("size")
|
||||||
options.delete("size")
|
options["cols"], options["rows"] = size.split("x")
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
# Creates a check box.
|
# Creates a check box.
|
||||||
def check_box_tag(name, value = "1", checked = false, options = {})
|
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 = { "type" => "checkbox", "name" => name, "id" => name, "value" => value }.update(options.stringify_keys)
|
||||||
html_options["checked"] = "checked" if checked
|
html_options["checked"] = "checked" if checked
|
||||||
tag("input", html_options)
|
tag :input, html_options
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates a radio button.
|
# Creates a radio button.
|
||||||
def radio_button_tag(name, value, checked = false, options = {})
|
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 = { "type" => "radio", "name" => name, "id" => name, "value" => value }.update(options.stringify_keys)
|
||||||
html_options["checked"] = "checked" if checked
|
html_options["checked"] = "checked" if checked
|
||||||
tag("input", html_options)
|
tag :input, html_options
|
||||||
end
|
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 = {})
|
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
|
end
|
||||||
|
|
||||||
# Displays an image which when clicked will submit the form.
|
# Displays an image which when clicked will submit the form.
|
||||||
#
|
#
|
||||||
# <tt>source</tt> is passed to AssetTagHelper#image_path
|
# <tt>source</tt> is passed to AssetTagHelper#image_path
|
||||||
def image_submit_tag(source, options = {})
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -94,6 +94,13 @@ class FormTagHelperTest < Test::Unit::TestCase
|
||||||
assert_dom_equal expected, actual
|
assert_dom_equal expected, actual
|
||||||
end
|
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
|
def test_pass
|
||||||
assert_equal 1, 1
|
assert_equal 1, 1
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue