Created
May 15, 2013 07:07
-
-
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/.
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
| # $("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