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

Javascript preventing double clicking of buttons doesn't work if page load time is higher than debounce timeout #2498

Closed
cjwood opened this issue Jan 13, 2022 · 2 comments

Comments

@cjwood
Copy link

cjwood commented Jan 13, 2022

In button.js where the "data-prevent-double-click" attribute is used to identify buttons that should not allow double clicks, a timeout is set on such buttons so that they cannot be activated again within the timeout period. The hardcoded timeout period stored against DEBOUNCE_TIMEOUT_IN_SECONDS is 1.

On occasions where the request takes >1 second to return it is possible to click the button again and re-send the request as the 1s timeout has expired, this results in another 1s timeout being set. If for example the request takes 4s to return, it is possible to send the request at least 4 times: the first time the button is clicked, 1s after the first click, 2s after the first click, 3s after the first click.

The prevention of double clicks should function correctly regardless of request time.

@cjwood
Copy link
Author

cjwood commented Jan 25, 2022

Our way of working around this has been to add an event listener to the form submit action disabling the form's buttons after the submission has completed to prevent further clicks. The button(s) become available again when the page refreshes.

@querkmachine
Copy link
Member

I think this may be a misunderstanding of what the attribute is for: it's there to prevent duplicate submissions caused by a double click action — aka, clicking the left mouse button twice in rapid succession, as one might do on a desktop icon.

It isn't intended to prevent clicking a button more than once generally, as how that behaves may have to be different depending on the architecture of the service.

@querkmachine querkmachine closed this as not planned Won't fix, can't repro, duplicate, stale Jun 17, 2024
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

No branches or pull requests

2 participants