Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling $(item).sortable('cancel') on Drop event of droppable disables sortable

I have some sortable connected list, that are at the same time droppable places. The problem is that when I call the cancel method of sortable in the drop event of droppable, the sortable is broken and wont work any more. Example http://jsfiddle.net/zSnBA/10/ try to move the div number 102 on the second list: you will see that the cancel event will be called but the sortable wont work any more? Any help?

like image 390
albanx Avatar asked Dec 28 '11 16:12

albanx


1 Answers

I would recommend not making the sortable list draggable as well, but listen to the receive event on sortable to cancel the event:

$('div.products-list').sortable({
    connectWith: '.products-list',
    placeholder: 'ui-state-highlight',
    items: 'div.product',
    revert: 200,
    receive: function(event, ui) {
        var prod_id = ui.item.attr("prod_id");

        /* Equal to 1 is valid because an item was just added to the list: */
        if ($(this).find(".product[prod_id='" + prod_id + "']").length > 1) {
            ui.sender.sortable("cancel");
        }
    }
});

Example: http://jsfiddle.net/z5X5y/

like image 85
Andrew Whitaker Avatar answered Nov 12 '22 09:11

Andrew Whitaker