bevacqua / angularjs-dragula

:ok_hand: Drag and drop so simple it hurts
https://bevacqua.github.io/angularjs-dragula
MIT License
509 stars 110 forks source link

.on('remove'...) not working correctly #61

Closed BillTheGoat closed 8 years ago

BillTheGoat commented 8 years ago

I am making a simple dragula image cloner with the possibility to remove images from the target element as well. This is my first time using Dragula, but I think this is a bug.

Using:

.on('drop', function(target) { var comDiv = findAncestor(target.parentNode, "myclass"); comDiv.setAttribute("c", "c"); })

I can successfully add an attribute to a parent div (findAncestor is a function to ... find an ancestor). It is no problem to remove images as expected. For some reason, I must add the .parentNode or this does not work.

However, If I add:

.on('remove', function(source) { var comDiv = findAncestor(source.parentNode, "myclass"); comDiv.setAttribute("c", "c"); })

I can no longer properly remove images: instead of disappearing, they remain visible outside of the source container, and if I drag that image it fires the event again. Further, I get a JS error: Uncaught TypeError: Cannot read property 'parentNode' of null

I looked a bit into the source but did not manage to locate what might be causing this.

BillTheGoat commented 8 years ago

I don't know if this helps, but if I drag the original image (not the cloned image) into the same container again, the first cloned image I dragged out and the new clone in the div will do a swap when I drag the new image out to remove it.

BillTheGoat commented 8 years ago

I just noticed I posted this in the wrong place. I am using vanilla dragula...