Jump to content


Draggable: Cancel Drag?

Recommended Posts

I have some code that checks conditions in the onDragStart handler. I'd like to be able to cancel the drag if a set of conditions are not met. I had assumed that returning false from handler would do it, but was wrong. Is there any clean way to cancel a drag in this case?


Link to comment
Share on other sites

I actually moved the check to onPress and just basically just disable then re-enable the Draggable if the check fails.

Link to comment
Share on other sites

Yep, Diaco is right, but technically you are supposed to pass in the event. Here's an excerpt from the docs:


You may force the Draggable to immediately stop interactively dragging by calling endDrag() and passing it the original mouse or touch event that initiated the stop - this is necessary because Draggable must inspect that event for various information like pageX, pageY, target, etc. You cannot callendDrag() without passing that original event.



So it should be as simple as:

  onPress:function(e){ if(!X){ this.endDrag(e) } }
  • Like 3
Link to comment
Share on other sites

The issue with calling endDrag() is that it triggers the onDragEnd handler, which does other processing I want to avoid in this case.


I suppose I could add something to the event object to let the handler know that I ended it due to my checks (as opposed to it being ended by the user letting up on the mouse button).



That's what I ended up doing. There are a couple situations that just adding some info to the event object being propagated helped me solve.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.