diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG.md | 4 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/form_tag_helper.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/url_helper.rb | 17 | ||||
-rw-r--r-- | actionpack/test/template/form_tag_helper_test.rb | 30 | ||||
-rw-r--r-- | actionpack/test/template/url_helper_test.rb | 32 |
5 files changed, 54 insertions, 31 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 815810c05a..705d0c9072 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,9 @@ ## Rails 3.2.4 (unreleased) ## +* Deprecate `:disable_with` in favor of `'data-disable-with'` option for `button_to` and `submit_tag` helpers. + + *Carlos Galdino + Rafael Mendonça França* + * Deprecate `:mouseover` options for `image_tag` helper. *Rafael Mendonça França* * Deprecate `button_to_function` and `link_to_function` helpers. *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 066b98d4a2..8ccffb4952 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -417,6 +417,8 @@ module ActionView 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.0. Use :data-disable-with instead" + options["data-disable-with"] = disable_with end diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 1f1cd3cee3..804b204fd1 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -301,7 +301,7 @@ module ActionView # # <div><input value="Create" type="submit" /></div> # # </form>" # - # + # # <%= button_to "Delete Image", { :action => "delete", :id => @image.id }, # :confirm => "Are you sure?", :method => :delete %> # # => "<form method="post" action="/images/delete/1" class="button_to"> @@ -317,7 +317,7 @@ module ActionView # # => "<form class='button_to' method='post' action='http://www.example.com' data-remote='true'> # # <div> # # <input name='_method' value='delete' type='hidden' /> - # # <input value='Destroy' type='submit' disable_with='loading...' data-confirm='Are you sure?' /> + # # <input value='Destroy' type='submit' data-disable-with='loading...' data-confirm='Are you sure?' /> # # </div> # # </form>" # # @@ -333,9 +333,9 @@ module ActionView form_method = method.to_s == 'get' ? 'get' : 'post' form_options = html_options.delete('form') || {} form_options[:class] ||= html_options.delete('form_class') || 'button_to' - + remote = html_options.delete('remote') - + request_token_tag = '' if form_method == 'post' && protect_against_forgery? request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token) @@ -350,7 +350,7 @@ module ActionView form_options.merge!(:method => form_method, :action => url) form_options.merge!("data-remote" => "true") if remote - + "#{tag(:form, form_options, true)}<div>#{method_tag}#{tag("input", html_options)}#{request_token_tag}</div></form>".html_safe end @@ -622,7 +622,12 @@ module ActionView confirm = html_options.delete('confirm') method = html_options.delete('method') - html_options["data-disable-with"] = disable_with if disable_with + if disable_with + ActiveSupport::Deprecation.warn ":disable_with option is deprecated and will be removed from Rails 4.0. Use :data-disable-with instead" + + html_options["data-disable-with"] = disable_with + end + 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 dcc6dd0411..1bfe2856dc 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -367,17 +367,21 @@ class FormTagHelperTest < ActionView::TestCase end def test_submit_tag - assert_dom_equal( - %(<input name='commit' data-disable-with="Saving..." onclick="alert('hello!')" type="submit" value="Save" />), - submit_tag("Save", :disable_with => "Saving...", :onclick => "alert('hello!')") - ) + assert_deprecated ":disable_with option is deprecated and will be removed from Rails 4.0. Use :data-disable-with instead" do + assert_dom_equal( + %(<input name='commit' data-disable-with="Saving..." onclick="alert('hello!')" type="submit" value="Save" />), + submit_tag("Save", :disable_with => "Saving...", :onclick => "alert('hello!')") + ) + end end def test_submit_tag_with_no_onclick_options - assert_dom_equal( - %(<input name='commit' data-disable-with="Saving..." type="submit" value="Save" />), - submit_tag("Save", :disable_with => "Saving...") - ) + assert_deprecated ":disable_with option is deprecated and will be removed from Rails 4.0. Use :data-disable-with instead" do + assert_dom_equal( + %(<input name='commit' data-disable-with="Saving..." type="submit" value="Save" />), + submit_tag("Save", :disable_with => "Saving...") + ) + end end def test_submit_tag_with_confirmation @@ -388,10 +392,12 @@ class FormTagHelperTest < ActionView::TestCase end def test_submit_tag_with_confirmation_and_with_disable_with - assert_dom_equal( - %(<input name="commit" data-disable-with="Saving..." data-confirm="Are you sure?" type="submit" value="Save" />), - submit_tag("Save", :disable_with => "Saving...", :confirm => "Are you sure?") - ) + assert_deprecated ":disable_with option is deprecated and will be removed from Rails 4.0. Use :data-disable-with instead" do + assert_dom_equal( + %(<input name="commit" data-disable-with="Saving..." data-confirm="Are you sure?" type="submit" value="Save" />), + submit_tag("Save", :disable_with => "Saving...", :confirm => "Are you sure?") + ) + end end def test_button_tag diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 734b6f3aef..b7f4a1c139 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -82,16 +82,18 @@ class UrlHelperTest < ActiveSupport::TestCase end def test_button_to_with_javascript_disable_with - assert_dom_equal( - "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\"><div><input data-disable-with=\"Greeting...\" type=\"submit\" value=\"Hello\" /></div></form>", - button_to("Hello", "http://www.example.com", :disable_with => "Greeting...") - ) + assert_deprecated ":disable_with option is deprecated and will be removed from Rails 4.0. Use :data-disable-with instead" do + assert_dom_equal( + "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\"><div><input data-disable-with=\"Greeting...\" type=\"submit\" value=\"Hello\" /></div></form>", + button_to("Hello", "http://www.example.com", :disable_with => "Greeting...") + ) + end end def test_button_to_with_remote_and_form_options assert_dom_equal "<form method=\"post\" action=\"http://www.example.com\" class=\"custom-class\" data-remote=\"true\" data-type=\"json\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com", :remote => true, :form => { :class => "custom-class", "data-type" => "json" } ) end - + def test_button_to_with_remote_and_javascript_confirm assert_dom_equal( "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\" data-remote=\"true\"><div><input data-confirm=\"Are you sure?\" type=\"submit\" value=\"Hello\" /></div></form>", @@ -100,17 +102,21 @@ class UrlHelperTest < ActiveSupport::TestCase end def test_button_to_with_remote_and_javascript_disable_with - assert_dom_equal( - "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\" data-remote=\"true\"><div><input data-disable-with=\"Greeting...\" type=\"submit\" value=\"Hello\" /></div></form>", - button_to("Hello", "http://www.example.com", :remote => true, :disable_with => "Greeting...") - ) + assert_deprecated ":disable_with option is deprecated and will be removed from Rails 4.0. Use :data-disable-with instead" do + assert_dom_equal( + "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\" data-remote=\"true\"><div><input data-disable-with=\"Greeting...\" type=\"submit\" value=\"Hello\" /></div></form>", + button_to("Hello", "http://www.example.com", :remote => true, :disable_with => "Greeting...") + ) + end end def test_button_to_with_remote_and_javascript_confirm_and_javascript_disable_with - assert_dom_equal( - "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\" data-remote=\"true\"><div><input data-disable-with=\"Greeting...\" data-confirm=\"Are you sure?\" type=\"submit\" value=\"Hello\" /></div></form>", - button_to("Hello", "http://www.example.com", :remote => true, :confirm => "Are you sure?", :disable_with => "Greeting...") - ) + assert_deprecated ":disable_with option is deprecated and will be removed from Rails 4.0. Use :data-disable-with instead" do + assert_dom_equal( + "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\" data-remote=\"true\"><div><input data-disable-with=\"Greeting...\" data-confirm=\"Are you sure?\" type=\"submit\" value=\"Hello\" /></div></form>", + button_to("Hello", "http://www.example.com", :remote => true, :confirm => "Are you sure?", :disable_with => "Greeting...") + ) + end end def test_button_to_with_remote_false |