Logo
Explore Help
Sign In
darkhelm/notifications-admin
1
0
Fork 0
You've already forked notifications-admin
mirror of https://github.com/GSA/notifications-admin.git synced 2026-02-12 14:34:05 -05:00
Code Issues Packages Projects Releases Wiki Activity
Files
bb16626209bf2a11cf2a9c8b671df36b0d486b16
notifications-admin/app/assets/javascripts/preventDuplicateFormSubmissions.js

31 lines
497 B
JavaScript
Raw Normal View History

Prevent doubling clicking form submissions 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)
2017-09-15 14:10:21 +01:00
(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);
})();
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.25.0 Page: 675ms Template: 124ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API