Skip to content

Conversation

@Benjamin-Couey
Copy link
Contributor

@Benjamin-Couey Benjamin-Couey commented Aug 14, 2025

Makes progress towards resolving #3689

Description

This PR modifies the helpers in app/helpers/ui_helper.rb that create buttons and links to always include the disable_with property. This property will, upon the first click, disable the button/link and change its text to a configurable value ("Please wait.." by default) to prevent the user from making multiple redundant requests when double clicking a button that modifies the database.

This should solve a large subset of issues with double clicks, though in my opinion there is further work that should be done.

Beyond what this PR addresses, there are a number of places where the site has links which make non-GET requests to the server. Ruby on Rails recommends against this and instead recommends using forms with submit buttons (such as those created by the button_to Action View URL Helper). Relevant to the issue this would guard against double clicks. In the future, I will work on another PR to refactor ui_helper and the broader site to replace these non-GET links with form.

In the discussion on the issue, the turbo_submits_with property was proposed as an alternative to disable_with. However, turbo_submits_with only works for buttons which submit a form and as mentioned above there are many cases where forms aren't used.

Additionally, Turbo is currently only enabled for a very small subset of controller actions (currently just the new and show actions of the app/controllers/distributionscontroller.rb) and enabling Turbo site-wide causes a number of tests to start failing. Diagnosing all of those tests and, if possible, reworking the site to work with Turbo enabled seemed outside the scope of this issue and so was set aside for now.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

I manually tested that double clicking on various buttons disabled them after the first click.

Automated tests were added for two pages where double clicks produced very noticeably unusual behavior to verify the addition of disable_with.

@@ -0,0 +1,24 @@
# Simulates the user double clicking on an element specified by a css_selector
# by using the API provided by Ferrum to manipulate the browser directly.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"We tried other techniques (built in double-click method, for example), but this is the way we were able to reliable cause double button press bugs to be triggered (and thus validate when they are fixed)"

Copy link
Collaborator

@awwaiid awwaiid left a comment

Choose a reason for hiding this comment

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

This looks good!

We walked through it all today and to clarify -- this improves the user-experience but we haven't found any actual double-submits yet. This makes the UX for users more obvious.

@awwaiid awwaiid merged commit 83508dc into rubyforgood:main Aug 17, 2025
11 checks passed
@github-actions
Copy link
Contributor

@Benjamin-Couey: Your PR 3689 check double clicks on submit is part of today's Human Essentials production release: 2025.08.24.
Thank you very much for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants