reppners / ngx-drag-drop

Angular directives using the native HTML Drag And Drop API
https://reppners.github.io/ngx-drag-drop/
BSD 3-Clause "New" or "Revised" License
299 stars 118 forks source link

Conditional dndMove #60

Closed androdel closed 5 years ago

androdel commented 5 years ago

Hi,

I have a node tree and every node in it is draggable and droppable at the same time. On drop, I check whether the drop is allowed. If allowed, the dragged node is added to the other node and should be removed from the node it came from.

I don't know why, but the "from" node doesn't get updated. I tried to fix this bij using the dndMove event. In here I can alter the "from" node but it always executes, even if the drop was not allowed.

Then I tried to store the "to" node locally so I can access it in the dndMove event (dndDrop executes before dndMove) to perform the allow check again but even then the local "to" is undefined.

Do you have any suggestions on how I can get around this issue? I'm stuck on this for days...

Kind regards

reppners commented 5 years ago

Hi,

I already saw your comment on #46 which should enable to use the separated dndDisableIf inputs to make it work. This is the intended way to either statically or dynamically disable dropping an item.

After the PR is merged you should be able to utilize the dndDragover event to run your custom logic to disable the dropzone dynamically via dndDisableDropIf based on the item you're dragging.

Since there are merge conflicts and the author did not respond to my request I may go ahead and do the necessary work on the branch of the PR to be able to merge it.

I don't know why, but the "from" node doesn't get updated.

That's intended, you are right that you need to update the "from" node manually in case of successful drop.

I tried to fix this bij using the dndMove event. In here I can alter the "from" node but it always executes, even if the drop was not allowed.

That's because the drop event is too late to disallow the drop as it already happened.

androdel commented 5 years ago

This will be on the next release, april 15?

reppners commented 5 years ago

You can try out dndDisableDragIf/ dndDisableDropIf in the current release candidate 2.0.0-rc.6

androdel commented 5 years ago

Thanks @reppners! It seems to work perfectly.