From 0106e5fe4436df1853a68c0ed792dc0cf3b9e1a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Galdino=20+=20Rafael=20Mendon=C3=A7a=20Fran=C3=A7?= =?UTF-8?q?a?= Date: Sat, 21 Jul 2012 16:19:40 -0300 Subject: Add back `:disable_with` and change deprecation horizon to 4.1 --- actionpack/CHANGELOG.md | 2 +- .../lib/action_view/helpers/form_tag_helper.rb | 22 ++++++++++++++++++ actionpack/lib/action_view/helpers/url_helper.rb | 19 +++++++++++++-- actionpack/test/template/form_tag_helper_test.rb | 9 +++++++- actionpack/test/template/url_helper_test.rb | 27 +++++++++++++++++++++- 5 files changed, 74 insertions(+), 5 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 38e48037fc..89c92730cd 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -95,7 +95,7 @@ * Templates without a handler extension now raises a deprecation warning but still defaults to ERb. In future releases, it will simply return the template contents. *Steve Klabnik* -* Remove `:disable_with` in favor of `'data-disable-with'` option from `submit_tag`, `button_tag` and `button_to` helpers. +* Deprecate `:disable_with` in favor of `:data => { :disable_with => "Text" }` option from `submit_tag`, `button_tag` and `button_to` helpers. *Carlos Galdino + Rafael Mendonça França* diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 87f1f4d92f..d7d9c45120 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -391,6 +391,9 @@ module ActionView # * :confirm => 'question?' - If present the unobtrusive JavaScript # drivers will provide a prompt with the question specified. If the user accepts, # the form is processed normally, otherwise no action is taken. + # * :disable_with - Value of this parameter will be used as the value for a + # disabled version of the submit button when the form is submitted. This feature is + # provided by the unobtrusive JavaScript driver. # # ==== Examples # submit_tag @@ -417,6 +420,12 @@ module ActionView def submit_tag(value = "Save changes", options = {}) options = options.stringify_keys + if disable_with = options.delete("disable_with") + ActiveSupport::Deprecation.warn ":disable_with option is deprecated and will be removed from Rails 4.1. Use ':data => { :disable_with => \'Text\' }' instead" + + options["data-disable-with"] = disable_with + end + if confirm = options.delete("confirm") ActiveSupport::Deprecation.warn ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead'" @@ -445,6 +454,10 @@ module ActionView # unobtrusive JavaScript drivers will provide a prompt with # the question specified. If the user accepts, the form is # processed normally, otherwise no action is taken. + # * :disable_with - Value of this parameter will be + # used as the value for a disabled version of the submit + # button when the form is submitted. This feature is provided + # by the unobtrusive JavaScript driver. # # ==== Examples # button_tag @@ -457,11 +470,20 @@ module ActionView # # Ask me! # # # + # button_tag "Checkout", :data => { disable_with => "Please wait..." } + # # => + # def button_tag(content_or_options = nil, options = nil, &block) options = content_or_options if block_given? && content_or_options.is_a?(Hash) options ||= {} options = options.stringify_keys + if disable_with = options.delete("disable_with") + ActiveSupport::Deprecation.warn ":disable_with option is deprecated and will be removed from Rails 4.1. Use ':data => { :disable_with => \'Text\' }' instead" + + options["data-disable-with"] = disable_with + end + if confirm = options.delete("confirm") ActiveSupport::Deprecation.warn ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead'" diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 04d9c69e43..3d86790a8f 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -165,6 +165,10 @@ module ActionView # * :confirm => 'question?' - This will allow the unobtrusive JavaScript # driver to prompt with the question specified. If the user accepts, the link is # processed normally, otherwise no action is taken. + # * :disable_with - Value of this parameter will be + # used as the value for a disabled version of the submit + # button when the form is submitted. This feature is provided + # by the unobtrusive JavaScript driver. # # ==== Examples # Because it relies on +url_for+, +link_to+ supports both older-style controller/action/id arguments @@ -285,6 +289,10 @@ module ActionView # * :confirm - This will use the unobtrusive JavaScript driver to # prompt with the question specified. If the user accepts, the link is # processed normally, otherwise no action is taken. + # * :disable_with - Value of this parameter will be + # used as the value for a disabled version of the submit + # button when the form is submitted. This feature is provided + # by the unobtrusive JavaScript driver. # # ==== Examples # <%= button_to "New", :action => "new" %> @@ -330,11 +338,11 @@ module ActionView # # # <%= button_to('Destroy', 'http://www.example.com', - # :method => "delete", :remote => true, :data => { :confirm' => 'Are you sure?' }) %> + # :method => "delete", :remote => true, :data => { :confirm' => 'Are you sure?', :disable_with => 'loading...' }) %> # # => "
# #
# # - # # + # # # # # #
# #
" @@ -635,6 +643,7 @@ module ActionView html_options = html_options.stringify_keys html_options['data-remote'] = 'true' if link_to_remote_options?(options) || link_to_remote_options?(html_options) + disable_with = html_options.delete("disable_with") confirm = html_options.delete('confirm') method = html_options.delete('method') @@ -646,6 +655,12 @@ module ActionView add_method_to_attributes!(html_options, method) if method + if disable_with + ActiveSupport::Deprecation.warn ":disable_with option is deprecated and will be removed from Rails 4.1. Use ':data => { :disable_with => \'Text\' }' instead" + + html_options["data-disable-with"] = disable_with + end + html_options else link_to_remote_options?(options) ? {'data-remote' => 'true'} : {} diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 72edb047cf..9afa4a2927 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -375,7 +375,14 @@ class FormTagHelperTest < ActionView::TestCase def test_submit_tag assert_dom_equal( %(), - submit_tag("Save", 'data-disable-with' => "Saving...", :onclick => "alert('hello!')") + submit_tag("Save", :onclick => "alert('hello!')", :data => { :disable_with => "Saving..." }) + ) + end + + def test_submit_tag_with_no_onclick_options + assert_dom_equal( + %(), + submit_tag("Save", :data => { :disable_with => "Saving..." }) ) end diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 893197a115..cb6f378ecb 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -106,10 +106,19 @@ class UrlHelperTest < ActiveSupport::TestCase def test_button_to_with_javascript_disable_with assert_dom_equal( "
", - button_to("Hello", "http://www.example.com", 'data-disable-with' => "Greeting...") + button_to("Hello", "http://www.example.com", :data => { :disable_with => "Greeting..." }) ) end + def test_button_to_with_javascript_deprecated_disable_with + assert_deprecated ":disable_with option is deprecated and will be removed from Rails 4.1. Use ':data => { :disable_with => \'Text\' }' instead" do + assert_dom_equal( + "
", + button_to("Hello", "http://www.example.com", :disable_with => "Greeting...") + ) + end + end + def test_button_to_with_remote_and_form_options assert_dom_equal "
", button_to("Hello", "http://www.example.com", :remote => true, :form => { :class => "custom-class", "data-type" => "json" } ) end @@ -130,6 +139,22 @@ class UrlHelperTest < ActiveSupport::TestCase end end + def test_button_to_with_remote_and_javascript_disable_with + assert_dom_equal( + "
", + button_to("Hello", "http://www.example.com", :remote => true, :data => { :disable_with => "Greeting..." }) + ) + end + + def test_button_to_with_remote_and_javascript_deprecated_disable_with + assert_deprecated ":disable_with option is deprecated and will be removed from Rails 4.1. Use ':data => { :disable_with => \'Text\' }' instead" do + assert_dom_equal( + "
", + button_to("Hello", "http://www.example.com", :remote => true, :disable_with => "Greeting...") + ) + end + end + def test_button_to_with_remote_false assert_dom_equal( "
", -- cgit v1.2.3