Skip to content

Instantly share code, notes, and snippets.

@ikks
Created August 1, 2014 12:58
Show Gist options
  • Save ikks/956796ec211f7b3ae461 to your computer and use it in GitHub Desktop.
Save ikks/956796ec211f7b3ae461 to your computer and use it in GitHub Desktop.
Avoid double click for fast clickers in Django admin
// Make sure you have this in a file invoked from the admin templating system
grp.jQuery(function(){
grp.jQuery.fn.preventDoubleSubmission = function() {
grp.jQuery(this).on('submit',function(e){
var the_form = grp.jQuery(this);
if (the_form.data('submitted') === true) {
// Previously submitted - don't submit again
e.preventDefault();
} else {
// Mark it so that the next submit can be ignored
the_form.data('submitted', true);
}
});
// Keep chainability
return this;
};
grp.jQuery('form').preventDoubleSubmission();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment