Skip to content

Instantly share code, notes, and snippets.

@henrik
Created May 15, 2013 07:07
Show Gist options
  • Save henrik/5582138 to your computer and use it in GitHub Desktop.
Save henrik/5582138 to your computer and use it in GitHub Desktop.
jQuery double submit prevention. Originally from http://thepugautomatic.com/2008/07/jquery-double-submission/.
# $("form:not([data-remote])").preventDoubleSubmit()
# http://henrik.nyh.se/2008/07/jquery-double-submission/
$ = jQuery
$.fn.preventDoubleSubmit = ->
ESC_KEYCODE = 27
form = this[0]
# Unprevent on ESC.
$(document).keyup (e) ->
if e.keyCode == ESC_KEYCODE
form.beenSubmitted = false
$(form).submit ->
if @beenSubmitted
return false
else
@beenSubmitted = true
return true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment