Created
March 22, 2012 15:52
-
-
Save kyledecot/2159149 to your computer and use it in GitHub Desktop.
Unobtrusive JS for submitting a delete link
This file contains 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('body').on('click', '[data-method="delete"]', function(event) { | |
event.preventDefault(); | |
var confirm_msg = jQuery(this).data('confirm'); | |
var form = jQuery('<form />').attr({ | |
method : 'POST', | |
action : jQuery(this).attr('href') | |
}); | |
var spoofer = jQuery('<input />').attr({ | |
type : 'hidden', | |
name : '__spoofer', | |
value : 'DELETE' | |
}); | |
form.append(spoofer); | |
if ((confirm_msg && confirm(confirm_msg)) || !confirm_message) { | |
form.trigger('submit'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment