Skip to content

Commit

Permalink
data-disable-with in button_to helper
Browse files Browse the repository at this point in the history
[#4993 state:committed]

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information
spastorino committed Oct 11, 2010
1 parent 448a187 commit 0c56a27
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions actionpack/lib/action_view/helpers/url_helper.rb
Expand Up @@ -589,6 +589,7 @@ def convert_options_to_data_attributes(options, html_options)
html_options['data-remote'] = 'true'
end

disable_with = html_options.delete("disable_with")
confirm = html_options.delete("confirm")

if html_options.key?("popup")
Expand All @@ -597,6 +598,7 @@ def convert_options_to_data_attributes(options, html_options)

method, href = html_options.delete("method"), html_options['href']

add_disable_with_to_attributes!(html_options, disable_with) if disable_with
add_confirm_to_attributes!(html_options, confirm) if confirm
add_method_to_attributes!(html_options, method) if method

Expand All @@ -607,6 +609,10 @@ def add_confirm_to_attributes!(html_options, confirm)
html_options["data-confirm"] = confirm if confirm
end

def add_disable_with_to_attributes!(html_options, disable_with)
html_options["data-disable-with"] = disable_with if disable_with
end

def add_method_to_attributes!(html_options, method)
html_options["rel"] = "nofollow" if method && method.to_s.downcase != "get"
html_options["data-method"] = method if method
Expand Down
21 changes: 21 additions & 0 deletions actionpack/test/template/url_helper_test.rb
Expand Up @@ -76,13 +76,34 @@ def test_button_to_with_javascript_confirm
)
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...")
)
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>",
button_to("Hello", "http://www.example.com", :remote => true, :confirm => "Are you sure?")
)
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

0 comments on commit 0c56a27

Please sign in to comment.