diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2017-01-03 13:46:30 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-03 13:46:30 -0500 |
commit | 058eb959bff8e43953f435bdf25d35435440d09e (patch) | |
tree | 248f248c050f9da825e45b004a9933b064968ea4 | |
parent | 2a7fcdad18e043b141eb2abe37bd5f241ca9c8c7 (diff) | |
parent | 3d2645ab138c9158ca4224458de74c723d4441cc (diff) | |
download | rails-058eb959bff8e43953f435bdf25d35435440d09e.tar.gz rails-058eb959bff8e43953f435bdf25d35435440d09e.tar.bz2 rails-058eb959bff8e43953f435bdf25d35435440d09e.zip |
Merge pull request #27548 from tylerhunt/fix-duplicate-disable-with
Prevent duplicate data-disable-with attributes
-rw-r--r-- | actionview/lib/action_view/helpers/form_tag_helper.rb | 32 | ||||
-rw-r--r-- | actionview/test/template/form_tag_helper_test.rb | 7 |
2 files changed, 25 insertions, 14 deletions
diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb index ffc52569f2..ffc64e7118 100644 --- a/actionview/lib/action_view/helpers/form_tag_helper.rb +++ b/actionview/lib/action_view/helpers/form_tag_helper.rb @@ -442,21 +442,9 @@ module ActionView # # => <input name='commit' type='submit' value='Save' data-disable-with="Save" data-confirm="Are you sure?" /> # def submit_tag(value = "Save changes", options = {}) - options = options.stringify_keys + options = options.deep_stringify_keys tag_options = { "type" => "submit", "name" => "commit", "value" => value }.update(options) - - if ActionView::Base.automatically_disable_submit_tag - unless tag_options["data-disable-with"] == false || (tag_options["data"] && tag_options["data"][:disable_with] == false) - disable_with_text = tag_options["data-disable-with"] - disable_with_text ||= tag_options["data"][:disable_with] if tag_options["data"] - disable_with_text ||= value.to_s.clone - tag_options.deep_merge!("data" => { "disable_with" => disable_with_text }) - else - tag_options["data"].delete(:disable_with) if tag_options["data"] - end - tag_options.delete("data-disable-with") - end - + set_default_disable_with value, tag_options tag :input, tag_options end @@ -898,6 +886,22 @@ module ActionView def sanitize_to_id(name) name.to_s.delete("]").tr("^-a-zA-Z0-9:.", "_") end + + def set_default_disable_with(value, tag_options) + return unless ActionView::Base.automatically_disable_submit_tag + data = tag_options["data"] + + unless tag_options["data-disable-with"] == false || (data && data["disable_with"] == false) + disable_with_text = tag_options["data-disable-with"] + disable_with_text ||= data["disable_with"] if data + disable_with_text ||= value.to_s.clone + tag_options.deep_merge!("data" => { "disable_with" => disable_with_text }) + else + data.delete("disable_with") if data + end + + tag_options.delete("data-disable-with") + end end end end diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb index 1248a0bb09..084c540139 100644 --- a/actionview/test/template/form_tag_helper_test.rb +++ b/actionview/test/template/form_tag_helper_test.rb @@ -510,6 +510,13 @@ class FormTagHelperTest < ActionView::TestCase ) end + def test_submit_tag_doesnt_have_data_disable_with_twice_with_hash + assert_equal( + %(<input type="submit" name="commit" value="Save" data-disable-with="Processing..." />), + submit_tag("Save", data: { disable_with: "Processing..." }) + ) + end + def test_submit_tag_with_symbol_value assert_dom_equal( %(<input data-disable-with="Save" name='commit' type="submit" value="Save" />), |