javascript - Undo action if "cancel" is pressed in response to confirm() -
i made quick list, can drag trash can (which removes it).
everything works when press "ok", , item gets removed told to. although if press "cancel" confirm popup, item shows in trash, , instead want go in list.
jsfiddle: http://jsfiddle.net/gdze8/2/
javascript:
$( init ) function init() { $(".contentitem").draggable({ revert: 'invalid' }); $(".list4").droppable( { accept: ".contentitem", drop: function(event, ui) { ui.draggable.hide(); if (confirm("are sure want delete?")){ ui.draggable.remove(); bottominfo (); } else { ui.draggable.show(); } return false; } }); }
you'll add confirm on draggable instead, reverting if confirm not confirmed etc :
$(".contentitem").draggable({ revert : function(event, ui) { var state = confirm("are sure want delete?"); if (state) $(this).remove(); return !state; } });
Comments
Post a Comment