Skip to content

Commit

Permalink
Fix that FormTagHelper#submit_tag using :disable_with should trigger …
Browse files Browse the repository at this point in the history
…the onsubmit handler of its form if available [DHH]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6134 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Feb 6, 2007
1 parent 9f31ecb commit 06b1198
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion actionpack/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*SVN*

# Fix #render_file so that TemplateError is called with the correct params and you don't get the WSOD. [Rick]
* Fix that FormTagHelper#submit_tag using :disable_with should trigger the onsubmit handler of its form if available [DHH]

* Fix #render_file so that TemplateError is called with the correct params and you don't get the WSOD. [Rick]

* Fix issue with deprecation messing up #template_root= usage. Add #prepend_view_path and #append_view_path to allow modification of a copy of the
superclass' view_paths. [Rick]
Expand Down
7 changes: 6 additions & 1 deletion actionpack/lib/action_view/helpers/form_tag_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ def submit_tag(value = "Save changes", options = {})
options.stringify_keys!

if disable_with = options.delete("disable_with")
options["onclick"] = "this.disabled=true;this.value='#{disable_with}';this.form.submit();#{options["onclick"]}"
options["onclick"] = [
"this.disabled=true",
"this.value='#{disable_with}'",
"#{options["onclick"]}",
"return (this.form.onsubmit ? this.form.onsubmit() : true)",
].join(";")
end

tag :input, { "type" => "submit", "name" => "commit", "value" => value }.update(options.stringify_keys)
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/template/form_tag_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_stringify_symbol_keys

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!')" />),
%(<input name='commit' type='submit' value='Save' onclick="this.disabled=true;this.value='Saving...';alert('hello!');return (this.form.onsubmit ? this.form.onsubmit() : true)" />),
submit_tag("Save", :disable_with => "Saving...", :onclick => "alert('hello!')")
)
end
Expand Down

0 comments on commit 06b1198

Please sign in to comment.