mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-06 11:23:48 -05:00
Have seen users complaining that they got an invitation email twice. This is probably because they clicked the button twice even though they think they only clicked it once. Double form submission is a common issue on web pages, and there are a number of different ways to prevent it. I’ve chosen to do it this way because: - temporarily, not permanently disabling the button means that this addresses the double clicking issue without breaking things if the user did, really want to click the button again deliberately (for whatever reason) - doing it with a `data` attribute, rather than the `disabled` attribute means that the interaction behaviour of the button doesn’t change ( `disabled` buttons can’t be focused, for example)
31 lines
497 B
JavaScript
31 lines
497 B
JavaScript
(function() {
|
|
|
|
"use strict";
|
|
|
|
let disableSubmitButtons = function(event) {
|
|
|
|
$submitButton = $(this).find(':submit');
|
|
|
|
if ($submitButton.data('clicked') == 'true') {
|
|
|
|
event.preventDefault();
|
|
|
|
} else {
|
|
|
|
$submitButton.data('clicked', 'true');
|
|
setTimeout(renableSubmitButton($submitButton), 1500);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let renableSubmitButton = $submitButton => () => {
|
|
|
|
$submitButton.data('clicked', '');
|
|
|
|
};
|
|
|
|
$('form').on('submit', disableSubmitButtons);
|
|
|
|
})();
|