diff --git a/src/sortable.js b/src/sortable.js index 8bdaaf9..9b6bf4e 100644 --- a/src/sortable.js +++ b/src/sortable.js @@ -348,7 +348,7 @@ angular.module('ui.sortable', []) // the value will be overwritten with the old value if (!ui.item.sortable.received) { ui.item.sortable.dropindex = getItemIndex(ui.item); - var droptarget = ui.item.closest('[ui-sortable], [data-ui-sortable], [x-ui-sortable]'); + var droptarget = ui.item.parent().closest('[ui-sortable], [data-ui-sortable], [x-ui-sortable]'); ui.item.sortable.droptarget = droptarget; ui.item.sortable.droptargetList = ui.item.parent(); diff --git a/test/sortable.e2e.nested.spec.js b/test/sortable.e2e.nested.spec.js index 874ba8c..9fb3f1b 100644 --- a/test/sortable.e2e.nested.spec.js +++ b/test/sortable.e2e.nested.spec.js @@ -128,6 +128,59 @@ describe('uiSortable', function() { }); }); + it('should update model when sorting between drectly nested sortables', function() { + inject(function($compile, $rootScope) { + var elementTree, li1, li2; + + elementTree = $compile(''.concat( + '
', + '
', + '
{{item.text}}
', + '
', + '
{{i.text}}
', + '
', + '
', + '
', + '
'))($rootScope); + + $rootScope.$apply(function() { + $rootScope.items = [ + { + text: 'Item 1', + items: [ + { text: 'Item 1.1', items: [] }, + { text: 'Item 1.2', items: [] } + ] + }, + { + text: 'Item 2', + items: [ + { text: 'Item 2.1', items: [] }, + { text: 'Item 2.2', items: [] } + ] + } + ]; + + $rootScope.sortableOptions = {}; + $rootScope.innerSortableOptions = { + connectWith: '.nested-sortable' + }; + }); + + host.append(elementTree); + + li1 = elementTree.find('.innerList:last'); + li2 = elementTree.find('.innerList:first'); + simulateElementDrag(li1, li2, { place: 'above', extradx: -10, extrady: -6 }); + expect($rootScope.items.map(function(x){ return x.text; })) + .toEqual(['Item 2', 'Item 1']); + expect($rootScope.items.map(function(x){ return x.text; })) + .toEqual(listInnerContent(elementTree, '.lvl1ItemContent')); + + $(elementTree).remove(); + }); + }); + }); }); \ No newline at end of file