Last active
October 28, 2015 01:18
-
-
Save bq1990/098fc8e30a4ec94b58d0 to your computer and use it in GitHub Desktop.
Prevent double submit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//from http://stackoverflow.com/questions/2830542/prevent-double-submission-of-forms-in-jquery | |
//usage: $('form').preventDoubleSubmission(); | |
//disable per form: $('form:not(.js-allow-double-submission)').preventDoubleSubmission(); | |
jQuery.fn.preventDoubleSubmission = function() { | |
$(this).on('submit',function(e){ | |
var $form = $(this); | |
if ($form.data('submitted') === true) { | |
// Previously submitted - don't submit again | |
e.preventDefault(); | |
} else { | |
// Mark it so that the next submit can be ignored | |
$form.data('submitted', true); | |
} | |
}); | |
// Keep chainability | |
return this; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment