From add1668a943a14044ab4dab36bd1d94db88ae527 Mon Sep 17 00:00:00 2001 From: Chris O'Meara Date: Mon, 6 Apr 2009 21:40:14 -0400 Subject: [PATCH] Fixed Javascript error on IE caused by reassigning an input's type attribute after cloning it from another input --- .../lib/action_view/helpers/form_tag_helper.rb | 10 +++++----- actionpack/test/template/form_tag_helper_test.rb | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 6d39a53..b45c81e 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -347,23 +347,23 @@ module ActionView # # name="commit" type="submit" value="Edit" /> 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"] = "if (window.hiddenCommit) { window.hiddenCommit.setAttribute('value', this.value); }" - options["onclick"] << "else { hiddenCommit = this.cloneNode(false);hiddenCommit.setAttribute('type', 'hidden');this.form.appendChild(hiddenCommit); }" + options["onclick"] = "if (!window.hiddenCommit) { hiddenCommit = document.createElement(this.tagName); hiddenCommit.setAttribute('type', 'hidden'); this.form.appendChild(hiddenCommit); }" + options["onclick"] << "hiddenCommit.setAttribute('name', this.name); hiddenCommit.setAttribute('value', this.value);" options["onclick"] << "this.setAttribute('originalValue', this.value);this.disabled = true;#{disable_with};" options["onclick"] << "result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());" options["onclick"] << "if (result == false) { this.value = this.getAttribute('originalValue');this.disabled = false; }return result;" end - + if confirm = options.delete("confirm") options["onclick"] ||= 'return true;' options["onclick"] = "if (!#{confirm_javascript_function(confirm)}) return false; #{options['onclick']}" end - + tag :input, { "type" => "submit", "name" => "commit", "value" => value }.update(options.stringify_keys) end diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index c713b8d..0d311b5 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -252,14 +252,14 @@ class FormTagHelperTest < ActionView::TestCase def test_submit_tag assert_dom_equal( - %(), + %(), submit_tag("Save", :disable_with => "Saving...", :onclick => "alert('hello!')") ) end def test_submit_tag_with_no_onclick_options assert_dom_equal( - %(), + %(), submit_tag("Save", :disable_with => "Saving...") ) end @@ -273,7 +273,7 @@ class FormTagHelperTest < ActionView::TestCase def test_submit_tag_with_confirmation_and_with_disable_with assert_dom_equal( - %(), + %(), submit_tag("Save", :disable_with => "Saving...", :confirm => "Are you sure?") ) end -- 1.6.0