ui-sortable icon indicating copy to clipboard operation
ui-sortable copied to clipboard

Helper function and connection lists bug

Open benmeiri opened this issue 12 years ago • 2 comments

When using sortable between two lists and a helper function (not 'clone') there is a problem if you drop an item at the last spot. The first time it works, the second time it will add it as the first element of the list. It continues this way for every even drop as the last item. You can check it here: http://codepen.io/anon/pen/FyaJs

This is what happened on your example when I dropped 'Youtube' as the last element. image

benmeiri avatar Jun 01 '14 11:06 benmeiri

After further investigation I see it happens also with helper:'clone' and not only with helper function

benmeiri avatar Jun 01 '14 12:06 benmeiri

I found the problem, it is in line 130 - you remove the last element if there is an helper, but you remove it from both the origin and the target list. I fixed it by checking that we are not in the origin list while removing the helper: original code: if (hasSortingHelper(element)) { // 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()); }

My fix: if (hasSortingHelper(element) && !ui.item.sortable.received) { // 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()); }

benmeiri avatar Jun 01 '14 14:06 benmeiri