Created
September 12, 2012 16:06
-
-
Save scottwater/3707728 to your computer and use it in GitHub Desktop.
Stop Double Submits and then re-enable the button (when validation fails/etc)
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
$ = jQuery | |
$.fn.extend | |
nodoublesubmit: (options) -> | |
settings = | |
delay: 2000 | |
debug: false | |
settings = $.extend settings, options | |
log = (msg) -> | |
console?.log msg if settings.debug | |
return @each (i, el)-> | |
log "Setting up deplay for #{settings.delay} milliseconds" | |
$el = ($ el) | |
$el.submit -> | |
$el.find('input[type="submit"]').attr('disabled', 'disabled'); | |
callback = -> | |
log "Callback for Fired" | |
$el.find('input[type="submit"]').removeAttr('disabled'); | |
setTimeout callback, settings.delay |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you're using jQuery 1.6.1+ you should probably be using
.prop('disabled', true)
and.prop('disabled', false)
instead of.attr
.