Skip to content
This repository
Browse code

Deprecate `:disable_with` in favor of `'data-disable-with'` option fo…

…r `button_to` and `submit_tag` helpers.
  • Loading branch information...
commit 21141e777bdce8534e3755c8de7268324b3d8714 1 parent 2506d4a
authored May 14, 2012
4  actionpack/CHANGELOG.md
Source Rendered
... ...
@@ -1,5 +1,9 @@
1 1
 ## Rails 3.2.4 (unreleased) ##
2 2
 
  3
+*   Deprecate `:disable_with` in favor of `'data-disable-with'` option for `button_to` and `submit_tag` helpers.
  4
+
  5
+    *Carlos Galdino + Rafael Mendonça França*
  6
+
3 7
 *   Deprecate `:mouseover` options for `image_tag` helper. *Rafael Mendonça França*
4 8
 
5 9
 *   Deprecate `button_to_function` and `link_to_function` helpers. *Rafael Mendonça França*
2  actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -417,6 +417,8 @@ def submit_tag(value = "Save changes", options = {})
417 417
         options = options.stringify_keys
418 418
 
419 419
         if disable_with = options.delete("disable_with")
  420
+          ActiveSupport::Deprecation.warn ":disable_with option is deprecated and will be removed from Rails 4.0. Use :data-disable-with instead"
  421
+
420 422
           options["data-disable-with"] = disable_with
421 423
         end
422 424
 
17  actionpack/lib/action_view/helpers/url_helper.rb
@@ -301,7 +301,7 @@ def link_to(*args, &block)
301 301
       #   #      <div><input value="Create" type="submit" /></div>
302 302
       #   #    </form>"
303 303
       #
304  
-      #      
  304
+      #
305 305
       #   <%= button_to "Delete Image", { :action => "delete", :id => @image.id },
306 306
       #             :confirm => "Are you sure?", :method => :delete %>
307 307
       #   # => "<form method="post" action="/images/delete/1" class="button_to">
@@ -317,7 +317,7 @@ def link_to(*args, &block)
317 317
       #   # => "<form class='button_to' method='post' action='http://www.example.com' data-remote='true'>
318 318
       #   #       <div>
319 319
       #   #         <input name='_method' value='delete' type='hidden' />
320  
-      #   #         <input value='Destroy' type='submit' disable_with='loading...' data-confirm='Are you sure?' />
  320
+      #   #         <input value='Destroy' type='submit' data-disable-with='loading...' data-confirm='Are you sure?' />
321 321
       #   #       </div>
322 322
       #   #     </form>"
323 323
       #   #
@@ -333,9 +333,9 @@ def button_to(name, options = {}, html_options = {})
333 333
         form_method = method.to_s == 'get' ? 'get' : 'post'
334 334
         form_options = html_options.delete('form') || {}
335 335
         form_options[:class] ||= html_options.delete('form_class') || 'button_to'
336  
-        
  336
+
337 337
         remote = html_options.delete('remote')
338  
-        
  338
+
339 339
         request_token_tag = ''
340 340
         if form_method == 'post' && protect_against_forgery?
341 341
           request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token)
@@ -350,7 +350,7 @@ def button_to(name, options = {}, html_options = {})
350 350
 
351 351
         form_options.merge!(:method => form_method, :action => url)
352 352
         form_options.merge!("data-remote" => "true") if remote
353  
-        
  353
+
354 354
         "#{tag(:form, form_options, true)}<div>#{method_tag}#{tag("input", html_options)}#{request_token_tag}</div></form>".html_safe
355 355
       end
356 356
 
@@ -622,7 +622,12 @@ def convert_options_to_data_attributes(options, html_options)
622 622
             confirm = html_options.delete('confirm')
623 623
             method  = html_options.delete('method')
624 624
 
625  
-            html_options["data-disable-with"] = disable_with if disable_with
  625
+            if disable_with
  626
+              ActiveSupport::Deprecation.warn ":disable_with option is deprecated and will be removed from Rails 4.0. Use :data-disable-with instead"
  627
+
  628
+              html_options["data-disable-with"] = disable_with
  629
+            end
  630
+
626 631
             html_options["data-confirm"] = confirm if confirm
627 632
             add_method_to_attributes!(html_options, method)   if method
628 633
 
30  actionpack/test/template/form_tag_helper_test.rb
@@ -367,17 +367,21 @@ def test_stringify_symbol_keys
367 367
   end
368 368
 
369 369
   def test_submit_tag
370  
-    assert_dom_equal(
371  
-      %(<input name='commit' data-disable-with="Saving..." onclick="alert('hello!')" type="submit" value="Save" />),
372  
-      submit_tag("Save", :disable_with => "Saving...", :onclick => "alert('hello!')")
373  
-    )
  370
+    assert_deprecated ":disable_with option is deprecated and will be removed from Rails 4.0. Use :data-disable-with instead" do
  371
+      assert_dom_equal(
  372
+        %(<input name='commit' data-disable-with="Saving..." onclick="alert('hello!')" type="submit" value="Save" />),
  373
+        submit_tag("Save", :disable_with => "Saving...", :onclick => "alert('hello!')")
  374
+      )
  375
+    end
374 376
   end
375 377
 
376 378
   def test_submit_tag_with_no_onclick_options
377  
-    assert_dom_equal(
378  
-      %(<input name='commit' data-disable-with="Saving..." type="submit" value="Save" />),
379  
-      submit_tag("Save", :disable_with => "Saving...")
380  
-    )
  379
+    assert_deprecated ":disable_with option is deprecated and will be removed from Rails 4.0. Use :data-disable-with instead" do
  380
+      assert_dom_equal(
  381
+        %(<input name='commit' data-disable-with="Saving..." type="submit" value="Save" />),
  382
+        submit_tag("Save", :disable_with => "Saving...")
  383
+      )
  384
+    end
381 385
   end
382 386
 
383 387
   def test_submit_tag_with_confirmation
@@ -388,10 +392,12 @@ def test_submit_tag_with_confirmation
388 392
   end
389 393
 
390 394
   def test_submit_tag_with_confirmation_and_with_disable_with
391  
-    assert_dom_equal(
392  
-      %(<input name="commit" data-disable-with="Saving..." data-confirm="Are you sure?" type="submit" value="Save" />),
393  
-      submit_tag("Save", :disable_with => "Saving...", :confirm => "Are you sure?")
394  
-    )
  395
+    assert_deprecated ":disable_with option is deprecated and will be removed from Rails 4.0. Use :data-disable-with instead" do
  396
+      assert_dom_equal(
  397
+        %(<input name="commit" data-disable-with="Saving..." data-confirm="Are you sure?" type="submit" value="Save" />),
  398
+        submit_tag("Save", :disable_with => "Saving...", :confirm => "Are you sure?")
  399
+      )
  400
+    end
395 401
   end
396 402
 
397 403
   def test_button_tag
32  actionpack/test/template/url_helper_test.rb
@@ -82,16 +82,18 @@ def test_button_to_with_javascript_confirm
82 82
   end
83 83
 
84 84
   def test_button_to_with_javascript_disable_with
85  
-    assert_dom_equal(
86  
-      "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\"><div><input data-disable-with=\"Greeting...\" type=\"submit\" value=\"Hello\" /></div></form>",
87  
-      button_to("Hello", "http://www.example.com", :disable_with => "Greeting...")
88  
-    )
  85
+    assert_deprecated ":disable_with option is deprecated and will be removed from Rails 4.0. Use :data-disable-with instead" do
  86
+      assert_dom_equal(
  87
+        "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\"><div><input data-disable-with=\"Greeting...\" type=\"submit\" value=\"Hello\" /></div></form>",
  88
+        button_to("Hello", "http://www.example.com", :disable_with => "Greeting...")
  89
+      )
  90
+    end
89 91
   end
90 92
 
91 93
   def test_button_to_with_remote_and_form_options
92 94
     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" } )
93 95
   end
94  
-  
  96
+
95 97
   def test_button_to_with_remote_and_javascript_confirm
96 98
     assert_dom_equal(
97 99
       "<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 @@ def test_button_to_with_remote_and_javascript_confirm
100 102
   end
101 103
 
102 104
   def test_button_to_with_remote_and_javascript_disable_with
103  
-    assert_dom_equal(
104  
-      "<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>",
105  
-      button_to("Hello", "http://www.example.com", :remote => true, :disable_with => "Greeting...")
106  
-    )
  105
+    assert_deprecated ":disable_with option is deprecated and will be removed from Rails 4.0. Use :data-disable-with instead" do
  106
+      assert_dom_equal(
  107
+        "<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>",
  108
+        button_to("Hello", "http://www.example.com", :remote => true, :disable_with => "Greeting...")
  109
+      )
  110
+    end
107 111
   end
108 112
 
109 113
   def test_button_to_with_remote_and_javascript_confirm_and_javascript_disable_with
110  
-    assert_dom_equal(
111  
-      "<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>",
112  
-      button_to("Hello", "http://www.example.com", :remote => true, :confirm => "Are you sure?", :disable_with => "Greeting...")
113  
-    )
  114
+    assert_deprecated ":disable_with option is deprecated and will be removed from Rails 4.0. Use :data-disable-with instead" do
  115
+      assert_dom_equal(
  116
+        "<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>",
  117
+        button_to("Hello", "http://www.example.com", :remote => true, :confirm => "Are you sure?", :disable_with => "Greeting...")
  118
+      )
  119
+    end
114 120
   end
115 121
 
116 122
   def test_button_to_with_remote_false

0 notes on commit 21141e7

Please sign in to comment.
Something went wrong with that request. Please try again.