Skip to content

Instantly share code, notes, and snippets.

@kyledecot
Created March 22, 2012 15:52
Show Gist options
  • Save kyledecot/2159149 to your computer and use it in GitHub Desktop.
Save kyledecot/2159149 to your computer and use it in GitHub Desktop.
Unobtrusive JS for submitting a delete link
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