mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-13 09:50:08 -04:00
Merge pull request #1490 from alphagov/prevent-duplicate-form-submissions
Prevent doubling clicking form submissions
This commit is contained in:
30
app/assets/javascripts/preventDuplicateFormSubmissions.js
Normal file
30
app/assets/javascripts/preventDuplicateFormSubmissions.js
Normal file
@@ -0,0 +1,30 @@
|
||||
(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);
|
||||
|
||||
})();
|
||||
@@ -67,6 +67,7 @@ gulp.task('javascripts', () => gulp
|
||||
paths.src + 'javascripts/listEntry.js',
|
||||
paths.src + 'javascripts/liveSearch.js',
|
||||
paths.src + 'javascripts/errorTracking.js',
|
||||
paths.src + 'javascripts/preventDuplicateFormSubmissions.js',
|
||||
paths.src + 'javascripts/main.js'
|
||||
])
|
||||
.pipe(plugins.prettyerror())
|
||||
|
||||
Reference in New Issue
Block a user