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

droptargetContext is undefined when sortable nested #532

Closed soonwait closed 7 years ago

soonwait commented 7 years ago

Like this

<div class="grid"
    data-ng-model="grid.data"
    data-ui-sortable="grid.rowSortableOptions">

    <div class="row"
        data-ng-repeat="row in grid.data track by $index"
        data-ng-model="row.cols"
        data-ui-sortable="grid.colSortableOptions">

        <div class="col"
            data-ng-repeat="col in row.cols track by $index"
            data-ng-model="col.cells"
            data-ui-sortable="grid.cellSortableOptions">

            <div class="cell"
                data-ng-repeat="cell in col.cells track by $index">
            </div>
        </div>
    </div>
</div>

I have fixed myself by writing 'if statement' in line 365, Like

                var droptargetContext = ui.item.sortable._getElementContext(droptarget);
                if(droptargetContext) {
                    ui.item.sortable.droptargetModel = droptargetContext.scope.ngModel;

                    // Cancel the sort (let ng-repeat do the sort for us)
                    // Don't cancel if this is the received list because it has
                    // already been canceled in the other list, and trying to cancel
                    // here will mess up the DOM.
                    element.sortable('cancel');
                }
thgreasi commented 7 years ago

That's quite interesting. Could you fork the provided nested sortable example to reproduce this, so that I can add a test case for that?

thgreasi commented 7 years ago

Something like this perhaps.

soonwait commented 7 years ago

OK, i have forked an example this

you should find out error in console, when drag col or row, which said:

sortable.min.js:8 Uncaught TypeError: Cannot read property 'scope' of undefined
    at HTMLDivElement.C.update (https://cdnjs.cloudflare.com/ajax/libs/angular-ui-sortable/0.17.1/sortable.min.js:8:3604)
    at HTMLDivElement.<anonymous> (https://cdnjs.cloudflare.com/ajax/libs/angular-ui-sortable/0.17.1/sortable.min.js:8:654)
    at t.(anonymous function).(anonymous function)._trigger (https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js:6:11090)
    at t.(anonymous function).(anonymous function)._trigger (https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js:13:2147)
    at t.(anonymous function).(anonymous function)._trigger (https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js:6:4499)
    at t.(anonymous function).(anonymous function).<anonymous> (https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js:13:869)
    at t.(anonymous function).(anonymous function)._clear (https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js:13:1993)
    at t.(anonymous function).(anonymous function)._clear (https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js:6:4499)
    at t.(anonymous function).(anonymous function)._mouseStop (https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js:12:16765)
    at t.(anonymous function).(anonymous function)._mouseStop (https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js:6:4499)
soonwait commented 7 years ago

I also meet another bug(i think), I'll desc that in another issue #534

thgreasi commented 7 years ago

Releasing a fix as v0.17.2. Thank for reporting.