diff --git a/src/sortable.js b/src/sortable.js index a18f046..065179c 100644 --- a/src/sortable.js +++ b/src/sortable.js @@ -133,7 +133,8 @@ angular.module('ui.sortable', []) // the start and stop of repeat sections and sortable doesn't // respect their order (even if we cancel, the order of the // comments are still messed up). - if (hasSortingHelper(element, ui) && !ui.item.sortable.received) { + if (hasSortingHelper(element, ui) && !ui.item.sortable.received && + element.sortable( 'option', 'appendTo' ) === 'parent') { // restore all the savedNodes except .ui-sortable-helper element // (which is placed last). That way it will be garbage collected. savedNodes = savedNodes.not(savedNodes.last()); diff --git a/test/sortable.e2e.spec.js b/test/sortable.e2e.spec.js index dc2cdaf..21923d2 100644 --- a/test/sortable.e2e.spec.js +++ b/test/sortable.e2e.spec.js @@ -381,6 +381,30 @@ describe('uiSortable', function() { }); }); + it('should work when "helper: clone" and "appendTo" options are used together', function() { + inject(function($compile, $rootScope) { + var element; + element = $compile('')($rootScope); + $rootScope.$apply(function() { + $rootScope.opts = { + helper: 'clone', + appendTo: 'body' + }; + $rootScope.items = ['One', 'Two', 'Three']; + }); + + host.append(element); + + var li = element.find(':eq(1)'); + var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight(); + li.simulate('drag', { dy: dy }); + expect($rootScope.items).toEqual(['One', 'Three', 'Two']); + expect($rootScope.items).toEqual(listContent(element)); + + $(element).remove(); + }); + }); + it('should work when "helper: clone" and "placeholder" options are used together.', function() { inject(function($compile, $rootScope) { var element; @@ -648,4 +672,4 @@ describe('uiSortable', function() { }); -}); \ No newline at end of file +});