Skip to content

Commit

Permalink
Revert "Revert "Remove :disable_with in favor of `'data-disable-wit…
Browse files Browse the repository at this point in the history
…h'` option from `submit_tag`, `button_tag` and `button_to` helpers.""

Finally remove `:disable_with` but use `:data => { :disable_with => ... }`
in examples to show off a better API (which looks nicer in Ruby 1.9)

This reverts commit a5c38a9.
  • Loading branch information
josevalim committed May 15, 2012
1 parent a5c38a9 commit dd42e89
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 57 deletions.
4 changes: 4 additions & 0 deletions actionpack/CHANGELOG.md
@@ -1,5 +1,9 @@
## 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
Expand Down
24 changes: 3 additions & 21 deletions actionpack/lib/action_view/helpers/form_tag_helper.rb
Expand Up @@ -386,9 +386,6 @@ def radio_button_tag(name, value, checked = false, options = {})
# drivers will provide a prompt with the question specified. If the user accepts,
# the form is processed normally, otherwise no action is taken.
# * <tt>:disabled</tt> - If true, the user will not be able to use this input.
# * <tt>:disable_with</tt> - 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
Expand All @@ -401,25 +398,21 @@ def radio_button_tag(name, value, checked = false, options = {})
# submit_tag "Save edits", :disabled => true
# # => <input disabled="disabled" name="commit" type="submit" value="Save edits" />
#
# submit_tag "Complete sale", :disable_with => "Please wait..."
# submit_tag "Complete sale", :data => { :disable_with => "Please wait..." }
# # => <input name="commit" data-disable-with="Please wait..." type="submit" value="Complete sale" />
#
# submit_tag nil, :class => "form_submit"
# # => <input class="form_submit" name="commit" type="submit" />
#
# submit_tag "Edit", :disable_with => "Editing...", :class => "edit_button"
# # => <input class="edit_button" data-disable-with="Editing..." name="commit" type="submit" value="Edit" />
# submit_tag "Edit", :class => "edit_button"
# # => <input class="edit_button" name="commit" type="submit" value="Edit" />
#
# submit_tag "Save", :confirm => "Are you sure?"
# # => <input name='commit' type='submit' value='Save' data-confirm="Are you sure?" />
#
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
Expand All @@ -441,10 +434,6 @@ def submit_tag(value = "Save changes", options = {})
# processed normally, otherwise no action is taken.
# * <tt>:disabled</tt> - If true, the user will not be able to
# use this input.
# * <tt>:disable_with</tt> - 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
Expand All @@ -458,18 +447,11 @@ def submit_tag(value = "Save changes", options = {})
# # <strong>Ask me!</strong>
# # </button>
#
# button_tag "Checkout", :disable_with => "Please wait..."
# # => <button data-disable-with="Please wait..." name="button" type="submit">Checkout</button>
#
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
Expand Down
6 changes: 2 additions & 4 deletions actionpack/lib/action_view/helpers/url_helper.rb
Expand Up @@ -322,11 +322,11 @@ def link_to(*args, &block)
#
#
# <%= button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?',
# :method => "delete", :remote => true, :disable_with => 'loading...') %>
# :method => "delete", :remote => true) %>
# # => "<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-confirm='Are you sure?' />
# # <input name="authenticity_token" type="hidden" value="10f2163b45388899ad4d5ae948988266befcb6c3d1b2451cf657a0c293d605a6"/>
# # </div>
# # </form>"
Expand Down Expand Up @@ -616,11 +616,9 @@ def convert_options_to_data_attributes(options, html_options)
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

Expand Down
16 changes: 1 addition & 15 deletions actionpack/test/template/form_tag_helper_test.rb
Expand Up @@ -375,14 +375,7 @@ def test_stringify_symbol_keys
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!')")
)
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...")
submit_tag("Save", 'data-disable-with' => "Saving...", :onclick => "alert('hello!')")
)
end

Expand All @@ -393,13 +386,6 @@ def test_submit_tag_with_confirmation
)
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?")
)
end

def test_button_tag
assert_dom_equal(
%(<button name="button" type="submit">Button</button>),
Expand Down
16 changes: 1 addition & 15 deletions actionpack/test/template/url_helper_test.rb
Expand Up @@ -97,7 +97,7 @@ def test_button_to_with_javascript_confirm
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...")
button_to("Hello", "http://www.example.com", 'data-disable-with' => "Greeting...")
)
end

Expand All @@ -112,20 +112,6 @@ def test_button_to_with_remote_and_javascript_confirm
)
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...")
)
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...")
)
end

def test_button_to_with_remote_false
assert_dom_equal(
"<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>",
Expand Down
4 changes: 2 additions & 2 deletions guides/source/ajax_on_rails.textile
Expand Up @@ -78,7 +78,7 @@ will produce

<ruby>
button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?',
:method => "delete", :remote => true, :disable_with => 'loading...')
:method => "delete", :remote => true, 'data-disable-with' => 'loading...')
</ruby>

will produce
Expand All @@ -87,7 +87,7 @@ will produce
<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>
</html>
Expand Down

0 comments on commit dd42e89

Please sign in to comment.