From a5c38a9c087e33d36397afc496be7c8e01b37ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 15 May 2012 09:55:30 +0200 Subject: Revert "Remove `:disable_with` in favor of `'data-disable-with'` option from `submit_tag`, `button_tag` and `button_to` helpers." `disable_with:` is much easier to type than `"data-disable-with" =>`, and the fact it uses "data-disable-with" => is an implementation concern, it should not affect the public API. This reverts commit 683fc4db00f496e5225928afb4d4e932e0fcdc48. --- actionpack/CHANGELOG.md | 4 ---- .../lib/action_view/helpers/form_tag_helper.rb | 24 +++++++++++++++++++--- actionpack/lib/action_view/helpers/url_helper.rb | 6 ++++-- actionpack/test/template/form_tag_helper_test.rb | 16 ++++++++++++++- actionpack/test/template/url_helper_test.rb | 16 ++++++++++++++- guides/source/ajax_on_rails.textile | 4 ++-- 6 files changed, 57 insertions(+), 13 deletions(-) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 432e90199a..c50b581cb5 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,9 +1,5 @@ ## Rails 4.0.0 (unreleased) ## -* Remove `:disable_with` in favor of `'data-disable-with'` option from `submit_tag`, `button_tag` and `button_to` helpers. - - *Carlos Galdino + Rafael Mendonça França* - * Remove `:mouseover` option from `image_tag` helper. *Rafael Mendonça França* * The `select` method (select tag) forces :include_blank if `required` is true and diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 74c7d8fa3f..248cc2f6a3 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -386,6 +386,9 @@ module ActionView # drivers will provide a prompt with the question specified. If the user accepts, # the form is processed normally, otherwise no action is taken. # * :disabled - If true, the user will not be able to use this input. + # * :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. # * Any other key creates standard HTML options for the tag. # # ==== Examples @@ -398,14 +401,14 @@ module ActionView # submit_tag "Save edits", :disabled => true # # => # - # submit_tag "Complete sale", 'data-disable-with' => "Please wait..." + # submit_tag "Complete sale", :disable_with => "Please wait..." # # => # # submit_tag nil, :class => "form_submit" # # => # - # submit_tag "Edit", :class => "edit_button" - # # => + # submit_tag "Edit", :disable_with => "Editing...", :class => "edit_button" + # # => # # submit_tag "Save", :confirm => "Are you sure?" # # => @@ -413,6 +416,10 @@ module ActionView def submit_tag(value = "Save changes", options = {}) options = options.stringify_keys + if disable_with = options.delete("disable_with") + options["data-disable-with"] = disable_with + end + if confirm = options.delete("confirm") options["data-confirm"] = confirm end @@ -434,6 +441,10 @@ module ActionView # processed normally, otherwise no action is taken. # * :disabled - If true, the user will not be able to # use this input. + # * :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. # * Any other key creates standard HTML options for the tag. # # ==== Examples @@ -447,11 +458,18 @@ module ActionView # # Ask me! # # # + # button_tag "Checkout", :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") + options["data-disable-with"] = disable_with + end + if confirm = options.delete("confirm") options["data-confirm"] = confirm end diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 7e69547dab..4986f9d8ae 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -322,11 +322,11 @@ module ActionView # # # <%= button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?', - # :method => "delete", :remote => true) %> + # :method => "delete", :remote => true, :disable_with => 'loading...') %> # # => "
# #
# # - # # + # # # # # #
# #
" @@ -616,9 +616,11 @@ 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') + html_options["data-disable-with"] = disable_with if disable_with html_options["data-confirm"] = confirm if confirm add_method_to_attributes!(html_options, method) if method diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 7a645217b8..1e92ff99ff 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", :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 @@ -386,6 +393,13 @@ class FormTagHelperTest < ActionView::TestCase ) end + def test_submit_tag_with_confirmation_and_with_disable_with + assert_dom_equal( + %(), + submit_tag("Save", :disable_with => "Saving...", :confirm => "Are you sure?") + ) + end + def test_button_tag assert_dom_equal( %(), diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index fb5b35bac6..eaa8bdbd26 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -97,7 +97,7 @@ 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", :disable_with => "Greeting...") ) end @@ -112,6 +112,20 @@ class UrlHelperTest < ActiveSupport::TestCase ) end + def test_button_to_with_remote_and_javascript_disable_with + assert_dom_equal( + "
", + button_to("Hello", "http://www.example.com", :remote => true, :disable_with => "Greeting...") + ) + end + + def test_button_to_with_remote_and_javascript_confirm_and_javascript_disable_with + assert_dom_equal( + "
", + button_to("Hello", "http://www.example.com", :remote => true, :confirm => "Are you sure?", :disable_with => "Greeting...") + ) + end + def test_button_to_with_remote_false assert_dom_equal( "
", diff --git a/guides/source/ajax_on_rails.textile b/guides/source/ajax_on_rails.textile index bfd007490a..cda9c64460 100644 --- a/guides/source/ajax_on_rails.textile +++ b/guides/source/ajax_on_rails.textile @@ -78,7 +78,7 @@ will produce button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?', - :method => "delete", :remote => true, 'data-disable-with' => 'loading...') + :method => "delete", :remote => true, :disable_with => 'loading...') will produce @@ -87,7 +87,7 @@ will produce
- +
-- cgit v1.2.3