From 31820b9dd60dc94744028b41f818f1fdab36e271 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 30 Jan 2010 20:22:15 -0600 Subject: Generate UJS code for :disable_with --- actionpack/lib/action_view/helpers/form_tag_helper.rb | 11 +---------- actionpack/lib/action_view/helpers/url_helper.rb | 4 ---- actionpack/test/template/form_tag_helper_test.rb | 6 +++--- 3 files changed, 4 insertions(+), 17 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 0e034d781a..fb32f78e5b 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -365,15 +365,7 @@ module ActionView 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 = document.createElement('input');hiddenCommit.type = 'hidden';" - options["onclick"] << "hiddenCommit.value = this.value;hiddenCommit.name = this.name;this.form.appendChild(hiddenCommit); }" - 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;" + options["data-disable-with"] = disable_with if disable_with end if confirm = options.delete("confirm") @@ -490,7 +482,6 @@ module ActionView def sanitize_to_id(name) name.to_s.gsub(']','').gsub(/[^-a-zA-Z0-9:.]/, "_") end - end end end diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 9e52275537..7d42a2ef69 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -588,10 +588,6 @@ module ActionView html_options["data-method"] = method if method end - def add_disable_with_to_attributes!(html_options, disable_with) - html_options["data-disable-with"] = disable_with if disable_with - end - def options_for_javascript(options) if options.empty? '{}' diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 41ab5c1621..01bde8ea04 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -285,14 +285,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 @@ -306,7 +306,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 -- cgit v1.2.3