0

My question is a duplicate of this question but the accepted answer contains a fiddle that is no more valid. So I need to ask it again.

I am using jquery Sortable to move elems from one list to another. On move I update the database accordingly but I need to move the elem back to its original position if the update on backend fails. How do I get this?

$(".connectedSortable").on("sortreceive", function (event, ui) {
    //fetch the data to the API
    if(data.status==200){
        //fetch was successful
    }else{
        //fetch failed
        //rollback to original position                     
    }
});

I think the exact code I am looking for was in the fiddle but it doesn't work anymore... Note that I am skipping all the code that is not necessary to explain the issue

1

1 Answer 1

0

Actually it is as simple as putting the cancel into the fail section

$(".connectedSortable").on("sortreceive", function (event, ui) {
    //fetch the data to the API
    if(data.status==200){
        //fetch was successful
    }else{
        //fetch failed
        //rollback to original position
        $('whatever selector you started sortable with').sortable("cancel");            
    }
});

is enough for rolling back the action.

Not the answer you're looking for? Browse other questions tagged or ask your own question.