marceljuenemann / angular-drag-and-drop-lists

Angular directives for sorting nested lists using the HTML5 Drag & Drop API
MIT License
2.16k stars 713 forks source link

How to disable list item removal when dragging outside of dnd-list #408

Closed rondog closed 7 years ago

rondog commented 7 years ago

I must be overlooking this option as I can't imagine this isn't something you can already do. When I drag an item out of the list the item gets deleted from the array. I need to disable that. Is that something I do in one of the callbacks? I cannot find this option.

rondog commented 7 years ago

anyone??

fberthel commented 7 years ago

Can you provide a plunkr or codepen demonstrating this behaviour?

In the simple lists example it works as exspected and doesnt delete the item if you drop it outside the lists.

The code used there to remove the item from the array is dnd-moved="list.splice($index, 1)", did you use dnd-dragend="list.splice($index, 1)" by accident? The dragend-callback is triggered wether or not you moved or moved it, it's also called when you drop the item outside any list. That would cause the behaviour you described I think (haven't tested it).

rondog commented 7 years ago

@fberthel I indeed used dnd-dragend. I ended up using that because my ng-repeat with an order by was creating weird duplicate entries. I have since changed the way my ordering works and am not using order by anymore but never changed back to dnd-moved Thanks for solving this.

fberthel commented 7 years ago

Had the same issues with order by, somewhere in the docs it states that you shouldn't use order by and also avoid using track by $index as this causes similar weird behaviour. You're welcome :)

rondog commented 7 years ago

I should read the docs more carefully :)