JQuery UI Sortable - prevents deletion of one specific list

I have 3 unordered list (for example, #list1, #list2and #list3), and now users can freely move any <li>of these three. How can I prevent any item from falling in #list3?

Users should be able to freely move items between #list1and #list2, as well as move items from #list3to any other list, but not toss the item at #list3(no matter which one it comes from).

+5
source share
2 answers

If you return false from the stopor method beforeStop, it will cancel the sort.

.ui-sortable-placeholder - , beforeStop, , #list3 :

myElement.sortable({
    beforeStop: function (event, ui) {
        if ($("#list3").find('.ui-sortable-placeholder').length) {
            // about to drop item into #list3, so cancel the sort
            return false;
        }
    }
});

:

, ( connectWith), , find():

$("#list1").sortable({
    connectWith: '#list2, #list3'
});
$("#list2").sortable({
    connectWith: '#list1, #list3'
});
$("#list3").sortable({
    connectWith: '#list1, #list3',
    stop: function() { return false; }
});

, , , .

+7

Try

$("#list1,#list2,#list3").sortable({
    connectWith: "#list1, #list2"
});

( , )

0

All Articles