jquery-sortable icon indicating copy to clipboard operation
jquery-sortable copied to clipboard

Revert/undo a drop

Open LarryBarker opened this issue 5 years ago • 1 comments

Have been working to handle an edge case where dropping an item fails. I am processing a request on the server side using onDrop and if the server throws an error, I would like to "undo" the drop so the item does not stick in the destination container, but effectively moves back to the container it was dragged from.

I looked at the only other issue similar to this, which was closed some time ago, but it doesn't appear to work. I have also tried detaching the item from the container it was dropped in, and then calling _super but this doesnt work either.

onDrop: function ($item, container, _super) {
            $.request('onDropItem', {
                error: function(jqXHR, textStatus, errorThrown) {
                    // revert/undo the drop here
                    _super($item, container.rootGroup.itemContainer);
            })
}

I believe container.rootGroup.itemContainer is a reference to the container the item was selected from? I thought calling _super() is what performs the actual drop?

Out of desperation, I thought maybe just using the same code from onDrop when it is successful, but using container.rootGroup.itemContainer would do it, but this hasn't worked either:

var $clonedItem = $("<li/>").css({ height: 0 });
                   $item.before($clonedItem);

                   $clonedItem.animate({ height: $item.height() });

                   $item.animate($clonedItem.position(), function () {
                       $clonedItem.detach();
                       _super($item, container.rootGroup.itemContainer);
                   });

Has anyone implemented this functionality before? Am I correct that container.rootGroup.itemContainer is a reference to the container the item originated from?

Any feedback is appreciated!

LarryBarker avatar Aug 03 '20 08:08 LarryBarker

@LarryBarker , I'm encountering a similar issue the canceling drop event. Were you able to find a workaround for this?

OluwoleOyetoke avatar May 31 '21 01:05 OluwoleOyetoke