Skip to content

Instantly share code, notes, and snippets.

@jakeboxer
Last active December 25, 2015 03:49
Show Gist options
  • Select an option

  • Save jakeboxer/6913132 to your computer and use it in GitHub Desktop.

Select an option

Save jakeboxer/6913132 to your computer and use it in GitHub Desktop.
# Prevent double-clicking on things, with fix for button value
$(document).on 'click', '[data-disable-with]', ->
$element = $(this)
this.disabled = true
if disableWith = $element.attr('data-disable-with')
$element.html(disableWith)
# This is a hilarious and gross fix to get the clicked button's name and
# value into the manually submitted form below, as it would be with a normal
# browser submit.
$("<input type='hidden' name='#{$element.attr('name')}' value='#{$element.val()}'>").prependTo($element)
# Disabling the button prevents the form from submitting, so we have to force
# the submit here.
$element.closest('form').submit()
false
# Prevent double-clicking on things
$(document).on 'click', '[data-disable-with]', ->
$element = $(this)
this.disabled = true
if disableWith = $element.attr('data-disable-with')
$element.html(disableWith)
# Disabling the button prevents the form from submitting, so we have to force
# the submit here.
$element.closest('form').submit()
false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment