Skip to content

Instantly share code, notes, and snippets.

@scottwater
Created September 12, 2012 16:06
Show Gist options
  • Save scottwater/3707728 to your computer and use it in GitHub Desktop.
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)
$ = 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
@stevenharman
Copy link

If you're using jQuery 1.6.1+ you should probably be using .prop('disabled', true) and .prop('disabled', false) instead of .attr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment