Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Sortable, delete current Item by drag out

Tags:

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/

like image 284
Peter Avatar asked Jul 31 '10 06:07

Peter


2 Answers

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.)

like image 136
Michael Finger Avatar answered Sep 21 '22 12:09

Michael Finger


This is the default behaviour of the out callback. See this jquery ui trac ticket

I really do not agree with the 'logical' behaviour notion.

"However, note that the "out" callback will still be triggered if you drag into a list and then release the mouse (but not if you're not over the list). This is logical behaviour and happens for normal sortables as well."

like image 39
redsquare Avatar answered Sep 23 '22 12:09

redsquare