I connected two lists with Sort. I have one list that contains available items to move to a real list containing a list of ordered items. My goal is to take an item from one list and transfer it to the second. When inserted into a new list, an update event will trigger a json database update.
The problem arises when you drop an element, and then: it
$("#sortable2").sortable({items: 'li'}).sortable('toArray')fires. Then I get a message Error: 'this.placeholder.0' is null or not an object.
Now in the recipient list, I can still move items to use them, and when the update event fires, it doesn't matter until I drop the new item into the list.
I found and tried to apply the error correction from http://dev.jqueryui.com/ticket/6054 , where it indicates a replacement:
this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
with
if(this.placeholder[0].parentNode)
this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
Additional details: I found a little closer that the error occurs when I receive a json error, and I try. $("#sortable2").sortable('cancel');I think now I will need to figure out how to cancel it when I moved the data to a list from another list.
This fix does not work. Does anyone know how to fix this?
Does anyone know how to return 2 lists back to the original with "cancel" if there is any error? Cancel is what throws an error.
My code is:
$(function() {
$("#sortable2").sortable({
connectWith: '.connectedSortable'
,
placeholder: 'ui-state-highlight'
,
items: 'li:not(.ui-state-disabled)'
,
receive: function(event, ui) {
},
remove: function(event, ui) {
},
update: function() {
$("#sortable2").sortable("refreshPositions");
}
})
$("#sortable1").sortable({
connectWith: '.connectedSortable'
,
placeholder: 'ui-state-highlight'
})
$("#sortable1 li, #sortable2 li").disableSelection();
});
function updateCycleSort() {
alert($("#sortable2").sortable({items: 'li'}).sortable('toArray'));
$.ajax({
type: "POST",
url: updateCycleSortUrl,
data: "cycles=" + $("#sortable2").sortable({items: 'li'}).sortable('toArray'),
dataType: "json",
success: function(response, textStatus, XMLHttpRequest) {
if (response.error == "false") {
}
else {
$("#sortable2").sortable('cancel');
alert("error");
}
},
error: function(response, textStatus, AjaxException) {
alert("BIG error " + response.statusText);
}
});
return false;
}