Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel the drop event #31

Closed
achatzi78 opened this issue Jun 24, 2016 · 4 comments
Closed

Cancel the drop event #31

achatzi78 opened this issue Jun 24, 2016 · 4 comments

Comments

@achatzi78
Copy link

Hi.

I was wondering if it is possible to cancel the drag & drop event if some criteria are not met. For example, I do not want an employee to be under a specific department under no circumstance.

I have already found a way to check if the dropZone should be valid or not but I have not found a way to return the dragged node to its previous position.

Is what I am asking even possible?

Thanks

@achatzi78
Copy link
Author

After I dug around a little bit more I found a way.

First of all I moved the triggerHandler to the top of the drop event handler, after the variable declarations. Since the triggerHandler returns a value, I assigned that value to a variable and if that variable is 1 then I continue with the changes in the DOM.

Is this way ok or I am missing something?

@dabeng
Copy link
Owner

dabeng commented Jun 28, 2016

Hi @achatzi78. I just published version 1.1.1 that provides option "dropCriteria" that could help users to limit the relationships between dragged node and drop zone. For more details, you could refer to http://dabeng.github.io/OrgChart/drag-drop/

@achatzi78
Copy link
Author

Excellent addition, well done!

This is much better way than my hack.

@dabeng dabeng closed this as completed Jun 28, 2016
@gazpachu
Copy link

gazpachu commented Nov 16, 2017

@dabeng AFAIK, the dropcriteria only works to allow or deny the drop, but what if we want to cancel the drop once it happened?

I'm asking because I'm showing a confirm modal dialog after the drop and I only want to accept the drop if the user click's on accept. If the user clicks on cancel then the drop wouldn't happen.

I've tried with event.stopPropagation() and event.preventDefault() but they don't cancel the drop. I've also tried with the dragend.orgchart event but it doesn't cancel the drag either.

Is there any other event I can use? like beforeNodeDropped?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants