Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use submit_tag auto-disabling when disable_with is set to false #40168

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions actionview/lib/action_view/helpers/form_tag_helper.rb
Expand Up @@ -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"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data = tag_options["data"]
data = tag_options.fetch("data", {})

This will save us from checking data && data["disable_with"] == false and also data.delete("disable_with") if data and disable_with_text ||= data["disable_with"] if data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KapilSachdev this broke our app. We have places where we're passing data: nil:

- data = { confirm: "sure?" } if doc.confirm?
= f.submit 'Update choice', data: 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")
Expand Down
10 changes: 10 additions & 0 deletions actionview/test/template/form_tag_helper_test.rb
Expand Up @@ -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(
%(<input name='commit' type="submit" value="Save" />),
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(
%(<input data-disable-with="Processing..." data-confirm="Are you sure?" name='commit' type="submit" value="Save" />),
Expand Down