angular-ui / ui-sortable

jQuery UI Sortable for AngularJS
http://angular-ui.github.io/ui-sortable/
MIT License
1.26k stars 444 forks source link

ui.item.sortable.* is undefined and does not run after a callback execute #542

Closed hieutranagi47 closed 6 years ago

hieutranagi47 commented 6 years ago

Hello team,

I drag/drop an item in my nested items, and I added a http request in update function to update data to my server side, if server side return true, I do nothing, if server side return false, I'll cancel the sort, but I can not cancel the sort with ui.item.sortable.cancel().

update: function(e, ui) { updateItemToServerSide(id) .then( function(res) { return; }, function(err) { ui.item.sortable('cancel'); } ); } updateItemToServerSide is my http service.

Thanks, Hieu Tran

thgreasi commented 6 years ago

That makes sense since by the time the async ajax request completes, the sorting will have already be complete, since nothing blocks the update callback. You should revert the changes based on the result. Please take a look at the Promised Reverting example found in README.