jQuery UI drop event of droppable fires on sortable

后端 未结 3 1510
暗喜
暗喜 2020-12-20 02:28

I have a list of elements that can be dropped into a list of (existing) sortables. When a droppable element is dropped into the sortables, I want to modify the element. I do

3条回答
  •  梦毁少年i
    2020-12-20 02:44

    I just ran into the same issue from a different angle. My sortable/droppable was firing off an over event and a drop event when all I wanted was the drop event. Using your code, here's how I fixed it:

        $('#sortable').sortable()
        $('#draggables li').draggable({
            connectToSortable: '#sortable',
            helper: 'clone',
            revert: 'invalid',
            cursor: 'move'
        });
        ​$('#sortable').sortable('disable'); 
        // disable the *sortable* functionality while retaining the *droppable*
        $('#sortable').droppable({
        // Drop should only fire when a draggable element is dropped into the sortables,
        // and NOT when the sortables themselves are sorted (without something being dragged into).
        drop: function(ev, ui){
            $(ui.draggable).html('
    TEMPLATE
    '); } });

    The only disadvantage is that all functionality within the sortable.update event must now be placed in the droppable.drop event.

提交回复
热议问题