Skip to content

Commit

Permalink
Ensure proper output when submit_tag is used with :disabled_with. [#388
Browse files Browse the repository at this point in the history
… state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
Scott Stewart authored and lifo committed Jul 2, 2008
1 parent b416c68 commit 67d5ac9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions actionpack/lib/action_view/helpers/form_tag_helper.rb
Expand Up @@ -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;",
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/template/form_tag_helper_test.rb
Expand Up @@ -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?');"/>),
Expand Down

0 comments on commit 67d5ac9

Please sign in to comment.