Jquery.UI.Sortable this.placeholder [0] .parentNode is null

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");
                    //updateCycleSort();
                }
            })

            $("#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") {
                        //$('div#resultRecordDetail').html(response.message);
                        //$('div#resultRecordDetail').addClass('success');
                        //autoHide(2500);
                    }
                    else {
                        $("#sortable2").sortable('cancel');
                        alert("error");
                    }
                },
                error: function(response, textStatus, AjaxException) {
                    alert("BIG error " + response.statusText);
                    //$('div.dialog-result').html(response.statusText);
                    //$('div.dialog-result').addClass('error').show();
                    //autoHide(10000);
                }
            });
            return false;
        }
+3
source share
1 answer
0

Source: https://habr.com/ru/post/1769167/


All Articles