Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ensure proper output when submit_tag is used with :disabled_with. [#388

… state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
commit 67d5ac93556dd62fe6d7721a154085f39c919035 1 parent b416c68
Scott Stewart authored lifo committed
View
6 actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -348,11 +348,13 @@ def submit_tag(value = "Save changes", options = {})
options.stringify_keys!
if disable_with = options.delete("disable_with")
+ disable_with = "this.value='#{disable_with}'"
+ disable_with << ";#{options.delete('onclick')}" if options['onclick']
+
options["onclick"] = [
"this.setAttribute('originalValue', this.value)",
"this.disabled=true",
- "this.value='#{disable_with}'",
- "#{options["onclick"]}",
+ disable_with,
"result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit())",
"if (result == false) { this.value = this.getAttribute('originalValue'); this.disabled = false }",
"return result;",
View
7 actionpack/test/template/form_tag_helper_test.rb
@@ -222,6 +222,13 @@ def test_submit_tag
)
end
+ def test_submit_tag_with_no_onclick_options
+ assert_dom_equal(
+ %(<input name='commit' type='submit' value='Save' onclick="this.setAttribute('originalValue', this.value);this.disabled=true;this.value='Saving...';result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = this.getAttribute('originalValue'); this.disabled = false };return result;" />),
+ submit_tag("Save", :disable_with => "Saving...")
+ )
+ end
+
def test_submit_tag_with_confirmation
assert_dom_equal(
%(<input name='commit' type='submit' value='Save' onclick="return confirm('Are you sure?');"/>),
Please sign in to comment.
Something went wrong with that request. Please try again.