Opened 8 years ago

Closed 7 years ago

#8162 closed bug (duplicate)

sortable does not properly clean up

Reported by: jjoemb Owned by:
Priority: minor Milestone: 1.9.0
Component: ui.sortable Version: 1.8.18
Keywords: Cc:
Blocked by: Blocking:

Description

I have a draggable, sortable, and droppable. When the sortable sorts within itself, the 'receive' event does not fire (as it shouldn't). However, if you drag an item from the draggable, through the sortable, then onto the droppable (with the net result of leaving the sortable unaffected), the sortable will fire 'receive' on the following sort, but not after that.

I've traced the code a bit, and it appears that the 'fromOutside' variable is set, even if the sortable had no net effect. When the next sort happens, it uses the previous value of 'fromOutside' to trigger the receive event. My only fix has been monkey patching; the sortable code is too complex for me to feel confident in fixing it.

Here is a fiddle that reproduces the problem: http://jsfiddle.net/GG8r8/1/

Change History (4)

comment:1 Changed 8 years ago by rdworth

Status: newopen

See related (though not duplicate) ticket #4303

comment:2 Changed 7 years ago by Skaffen

I've also hit this - it's when the draggable is using "connectToSortable" with the sortable in question and, as the original reporter says, when a draggable is dragged over the sortable but then dragged out again and dropped elsewhere (it doesn't have to be dropped onto a droppable, just dropping it anywhere outside that sortable will leave the sortable with fromOutside set).

The drag method in the "connectToSortable" bit is what sets fromOutside (just after a comment saying "hack so receive/update callbacks work (mostly)", as well as a chunk of other stuff, on the sortable if "this.instance._intersectsWith(this.instance.containerCache)" is true and if "!this.instance.isOver" is also true. If it doesn't intersect but isOver then it does some cleanup, but that cleanup is missing clearing fromOutside.

So I think is needed is after the line in the connectToSortable drag method which reads "inst.dropped = false; draggable revert needs that" is to have a line reading "this.instance.fromOutside = false;" - see code fragment below:

    //Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
    this.instance.currentItem.remove();
    if(this.instance.placeholder) this.instance.placeholder.remove();

    inst._trigger("fromSortable", event);
    inst.dropped = false; //draggable revert needs that
    this.instance.fromOutside = false;
}

I've tried out this one line fix with the case I was hitting, and it seems to work (the original receive event still fires when it should as well).

comment:3 Changed 7 years ago by jjoemb

I believe this is a dup of #8430 (well, really the other way around).

comment:4 Changed 7 years ago by Scott González

Resolution: duplicate
Status: openclosed
Note: See TracTickets for help on using tickets.