Skip to content
This repository
Browse code

Remove `:disable_with` in favor of `'data-disable-with'` option from …

…`submit_tag`, `button_tag` and `button_to` helpers.
  • Loading branch information...
commit 683fc4db00f496e5225928afb4d4e932e0fcdc48 1 parent c5bcb0d
authored May 14, 2012
4  actionpack/CHANGELOG.md
Source Rendered
... ...
@@ -1,5 +1,9 @@
1 1
 ## Rails 4.0.0 (unreleased) ##
2 2
 
  3
+*   Remove `:disable_with` in favor of `'data-disable-with'` option from `submit_tag`, `button_tag` and `button_to` helpers.
  4
+
  5
+    *Carlos Galdino + Rafael Mendonça França*
  6
+
3 7
 *   Remove `:mouseover` option from `image_tag` helper. *Rafael Mendonça França*
4 8
 
5 9
 *   The `select` method (select tag) forces :include_blank  if `required` is true and
24  actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -386,9 +386,6 @@ def radio_button_tag(name, value, checked = false, options = {})
386 386
       #   drivers will provide a prompt with the question specified. If the user accepts,
387 387
       #   the form is processed normally, otherwise no action is taken.
388 388
       # * <tt>:disabled</tt> - If true, the user will not be able to use this input.
389  
-      # * <tt>:disable_with</tt> - Value of this parameter will be used as the value for a
390  
-      #   disabled version of the submit button when the form is submitted. This feature is
391  
-      #   provided by the unobtrusive JavaScript driver.
392 389
       # * Any other key creates standard HTML options for the tag.
393 390
       #
394 391
       # ==== Examples
@@ -401,14 +398,14 @@ def radio_button_tag(name, value, checked = false, options = {})
401 398
       #   submit_tag "Save edits", :disabled => true
402 399
       #   # => <input disabled="disabled" name="commit" type="submit" value="Save edits" />
403 400
       #
404  
-      #   submit_tag "Complete sale", :disable_with => "Please wait..."
  401
+      #   submit_tag "Complete sale", 'data-disable-with' => "Please wait..."
405 402
       #   # => <input name="commit" data-disable-with="Please wait..." type="submit" value="Complete sale" />
406 403
       #
407 404
       #   submit_tag nil, :class => "form_submit"
408 405
       #   # => <input class="form_submit" name="commit" type="submit" />
409 406
       #
410  
-      #   submit_tag "Edit", :disable_with => "Editing...", :class => "edit_button"
411  
-      #   # => <input class="edit_button" data-disable-with="Editing..." name="commit" type="submit" value="Edit" />
  407
+      #   submit_tag "Edit", :class => "edit_button"
  408
+      #   # => <input class="edit_button" name="commit" type="submit" value="Edit" />
412 409
       #
413 410
       #   submit_tag "Save", :confirm => "Are you sure?"
414 411
       #   # => <input name='commit' type='submit' value='Save' data-confirm="Are you sure?" />
@@ -416,10 +413,6 @@ def radio_button_tag(name, value, checked = false, options = {})
416 413
       def submit_tag(value = "Save changes", options = {})
417 414
         options = options.stringify_keys
418 415
 
419  
-        if disable_with = options.delete("disable_with")
420  
-          options["data-disable-with"] = disable_with
421  
-        end
422  
-
423 416
         if confirm = options.delete("confirm")
424 417
           options["data-confirm"] = confirm
425 418
         end
@@ -441,10 +434,6 @@ def submit_tag(value = "Save changes", options = {})
441 434
       #   processed normally, otherwise no action is taken.
442 435
       # * <tt>:disabled</tt> - If true, the user will not be able to
443 436
       #   use this input.
444  
-      # * <tt>:disable_with</tt> - Value of this parameter will be
445  
-      #   used as the value for a disabled version of the submit
446  
-      #   button when the form is submitted. This feature is provided
447  
-      #   by the unobtrusive JavaScript driver.
448 437
       # * Any other key creates standard HTML options for the tag.
449 438
       #
450 439
       # ==== Examples
@@ -458,18 +447,11 @@ def submit_tag(value = "Save changes", options = {})
458 447
       #   #     <strong>Ask me!</strong>
459 448
       #   #    </button>
460 449
       #
461  
-      #   button_tag "Checkout", :disable_with => "Please wait..."
462  
-      #   # => <button data-disable-with="Please wait..." name="button" type="submit">Checkout</button>
463  
-      #
464 450
       def button_tag(content_or_options = nil, options = nil, &block)
465 451
         options = content_or_options if block_given? && content_or_options.is_a?(Hash)
466 452
         options ||= {}
467 453
         options = options.stringify_keys
468 454
 
469  
-        if disable_with = options.delete("disable_with")
470  
-          options["data-disable-with"] = disable_with
471  
-        end
472  
-
473 455
         if confirm = options.delete("confirm")
474 456
           options["data-confirm"] = confirm
475 457
         end
6  actionpack/lib/action_view/helpers/url_helper.rb
@@ -322,11 +322,11 @@ def link_to(*args, &block)
322 322
       #
323 323
       #
324 324
       #   <%= button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?',
325  
-      #             :method => "delete", :remote => true, :disable_with => 'loading...') %>
  325
+      #             :method => "delete", :remote => true) %>
326 326
       #   # => "<form class='button_to' method='post' action='http://www.example.com' data-remote='true'>
327 327
       #   #       <div>
328 328
       #   #         <input name='_method' value='delete' type='hidden' />
329  
-      #   #         <input value='Destroy' type='submit' disable_with='loading...' data-confirm='Are you sure?' />
  329
+      #   #         <input value='Destroy' type='submit' data-confirm='Are you sure?' />
330 330
       #   #         <input name="authenticity_token" type="hidden" value="10f2163b45388899ad4d5ae948988266befcb6c3d1b2451cf657a0c293d605a6"/>
331 331
       #   #       </div>
332 332
       #   #     </form>"
@@ -616,11 +616,9 @@ def convert_options_to_data_attributes(options, html_options)
616 616
             html_options = html_options.stringify_keys
617 617
             html_options['data-remote'] = 'true' if link_to_remote_options?(options) || link_to_remote_options?(html_options)
618 618
 
619  
-            disable_with = html_options.delete("disable_with")
620 619
             confirm = html_options.delete('confirm')
621 620
             method  = html_options.delete('method')
622 621
 
623  
-            html_options["data-disable-with"] = disable_with if disable_with
624 622
             html_options["data-confirm"] = confirm if confirm
625 623
             add_method_to_attributes!(html_options, method) if method
626 624
 
16  actionpack/test/template/form_tag_helper_test.rb
@@ -375,14 +375,7 @@ def test_stringify_symbol_keys
375 375
   def test_submit_tag
376 376
     assert_dom_equal(
377 377
       %(<input name='commit' data-disable-with="Saving..." onclick="alert('hello!')" type="submit" value="Save" />),
378  
-      submit_tag("Save", :disable_with => "Saving...", :onclick => "alert('hello!')")
379  
-    )
380  
-  end
381  
-
382  
-  def test_submit_tag_with_no_onclick_options
383  
-    assert_dom_equal(
384  
-      %(<input name='commit' data-disable-with="Saving..." type="submit" value="Save" />),
385  
-      submit_tag("Save", :disable_with => "Saving...")
  378
+      submit_tag("Save", 'data-disable-with' => "Saving...", :onclick => "alert('hello!')")
386 379
     )
387 380
   end
388 381
 
@@ -393,13 +386,6 @@ def test_submit_tag_with_confirmation
393 386
     )
394 387
   end
395 388
 
396  
-  def test_submit_tag_with_confirmation_and_with_disable_with
397  
-    assert_dom_equal(
398  
-      %(<input name="commit" data-disable-with="Saving..." data-confirm="Are you sure?" type="submit" value="Save" />),
399  
-      submit_tag("Save", :disable_with => "Saving...", :confirm => "Are you sure?")
400  
-    )
401  
-  end
402  
-
403 389
   def test_button_tag
404 390
     assert_dom_equal(
405 391
       %(<button name="button" type="submit">Button</button>),
16  actionpack/test/template/url_helper_test.rb
@@ -97,7 +97,7 @@ def test_button_to_with_javascript_confirm
97 97
   def test_button_to_with_javascript_disable_with
98 98
     assert_dom_equal(
99 99
       "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\"><div><input data-disable-with=\"Greeting...\" type=\"submit\" value=\"Hello\" /></div></form>",
100  
-      button_to("Hello", "http://www.example.com", :disable_with => "Greeting...")
  100
+      button_to("Hello", "http://www.example.com", 'data-disable-with' => "Greeting...")
101 101
     )
102 102
   end
103 103
 
@@ -112,20 +112,6 @@ def test_button_to_with_remote_and_javascript_confirm
112 112
     )
113 113
   end
114 114
 
115  
-  def test_button_to_with_remote_and_javascript_disable_with
116  
-    assert_dom_equal(
117  
-      "<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>",
118  
-      button_to("Hello", "http://www.example.com", :remote => true, :disable_with => "Greeting...")
119  
-    )
120  
-  end
121  
-
122  
-  def test_button_to_with_remote_and_javascript_confirm_and_javascript_disable_with
123  
-    assert_dom_equal(
124  
-      "<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>",
125  
-      button_to("Hello", "http://www.example.com", :remote => true, :confirm => "Are you sure?", :disable_with => "Greeting...")
126  
-    )
127  
-  end
128  
-
129 115
   def test_button_to_with_remote_false
130 116
     assert_dom_equal(
131 117
       "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>",
4  guides/source/ajax_on_rails.textile
Source Rendered
@@ -78,7 +78,7 @@ will produce
78 78
 
79 79
 <ruby>
80 80
 button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?',
81  
-          :method => "delete", :remote => true, :disable_with => 'loading...')
  81
+          :method => "delete", :remote => true, 'data-disable-with' => 'loading...')
82 82
 </ruby>
83 83
 
84 84
 will produce
@@ -87,7 +87,7 @@ will produce
87 87
 <form class='button_to' method='post' action='http://www.example.com' data-remote='true'>
88 88
   <div>
89 89
     <input name='_method' value='delete' type='hidden' />
90  
-    <input value='Destroy' type='submit' disable_with='loading...' data-confirm='Are you sure?' />
  90
+    <input value='Destroy' type='submit' data-disable-with='loading...' data-confirm='Are you sure?' />
91 91
   </div>
92 92
 </form>
93 93
 </html>

11 notes on commit 683fc4d

Sergey Kojin
skojin commented on 683fc4d May 14, 2012

looks strange for me, then also need replace others
remote: true -> 'data-remote' => true
confirm: 'message' -> 'data-confirm' => 'message'

José Valim
Owner

Why there is no deprecation? I am also not pleased with this changed, we are changing an API based on its implementation concerns.

Rafael Mendonça França
Owner

The deprecation was introduced in the 3-2-stable branch.

remote: true is infrastructure-level UJS changes how the Rails behavior.

disable_with is a UI level UJS that can be easily implemented in your application.

José Valim
Owner

@rafaelfranca Agreed, thanks for the explanation. Also, if we are removing UI concerns from the UJS related API, maybe we should get rid of data-confirm as well?

Rafael Mendonça França
Owner

Yes. I'll remove it too.

Claudio Poli

Any particular reason why this got backported in 3.2?

Claudio Poli

By the way 'data-remote' => true really disturbs me a little, especially if using Ruby 1.9 syntax.

Piotr Sarnacki
Collaborator
drogus commented on 683fc4d May 15, 2012

@masterkain it was not backported to 3.2, there is only a deprecation warning there

José Valim
Owner
Claudio Poli

nice, thanks ;)

Rafael Mendonça França
Owner

@masterkain also we are not going to remove :remote option.

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