Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert/undo a drop #280

Open
LarryBarker opened this issue Aug 3, 2020 · 1 comment
Open

Revert/undo a drop #280

LarryBarker opened this issue Aug 3, 2020 · 1 comment

Comments

@LarryBarker
Copy link

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!

@OluwoleOyetoke
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants