From a0fe1e77ad6e7c7510fc8d25ce2827385c9e7124 Mon Sep 17 00:00:00 2001 From: igor04 Date: Thu, 3 Sep 2020 18:21:52 +0300 Subject: [PATCH] Do not use disable_with when it set to false If automatically_disable_submit_tag is set to false then disable_with is ignored, as result in all cases where disable_with is explicitly set to false will produce unexpected result --- actionview/lib/action_view/helpers/form_tag_helper.rb | 7 +++---- actionview/test/template/form_tag_helper_test.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb index 8aab12e305ccb..505366b8b8210 100644 --- a/actionview/lib/action_view/helpers/form_tag_helper.rb +++ b/actionview/lib/action_view/helpers/form_tag_helper.rb @@ -897,16 +897,15 @@ def sanitize_to_id(name) 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) + if tag_options["data-disable-with"] == false || (data && data["disable_with"] == false) + data.delete("disable_with") if data + elsif ActionView::Base.automatically_disable_submit_tag 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") diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb index 80afed96e5876..17c2fe4f79b38 100644 --- a/actionview/test/template/form_tag_helper_test.rb +++ b/actionview/test/template/form_tag_helper_test.rb @@ -538,6 +538,16 @@ def test_empty_submit_tag_with_opt_out ActionView::Base.automatically_disable_submit_tag = true end + def test_empty_submit_tag_with_opt_out_and_explicit_disabling + ActionView::Base.automatically_disable_submit_tag = false + assert_dom_equal( + %(), + submit_tag("Save", data: { disable_with: false }) + ) + ensure + ActionView::Base.automatically_disable_submit_tag = true + end + def test_submit_tag_having_data_disable_with_string assert_dom_equal( %(),