Jquery Sortable, delete current Item by drag out

Peter picture Peter · Jul 31, 2010 · Viewed 19.3k times · Source

My Problem: The sortable event out: fires when I drag something in the list or when I sort the list. But I only want to start the function when I drag an item out.

My code

        $(document).ready(function ust()
        {    
            $('#div1').sortable({
                out: function(event, ui) { $('#nfo').append('OUT<br />'); }
            });

        });

Working example http://jsfiddle.net/FrbW8/22/

Answer

Michael Finger picture Michael Finger · Dec 9, 2010

Use beforeStop to intercept the item and remove it:

receive: function(e, ui) { sortableIn = 1; },
over: function(e, ui) { sortableIn = 1; },
out: function(e, ui) { sortableIn = 0; },
beforeStop: function(e, ui) {
   if (sortableIn == 0) { 
      ui.item.remove(); 
   } 
}

(I originally found this in the Google, but can no longer find the link. So, I apologize for not referencing the source.)