Created
August 1, 2014 12:58
-
-
Save ikks/956796ec211f7b3ae461 to your computer and use it in GitHub Desktop.
Avoid double click for fast clickers in Django admin
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
// 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