Again, I’ve seen the question asked on several occasions regarding how to cancel a drag of an item between List components. The List components all have the drag events: dragEnter, dragExit, dragOver, dragComplete, and dragDrop. Each of these can be overridden with a custom event handler. If you call event.preventDefault() in your custom event handler, you will cancel the default behavior of this event in the List classes. For example, in the sample below, I call event.preventDefault() within the custom dragDrop handler of the destination List. This causes the item to not get added to the destination List and the item is not removed from the initiating List. When you are deciding which events to customize to achieve the drag and drop action you want, you can use this as a general summary of what each event does:
|dragStart: This event is triggered on the initiating List. A dragSource is created and the drag begins by calling doDrag on the DragManager.dragEnter: This event is triggered on the target destination List. In the event handler, a drag is accepted or rejected. Drop feedback is shown depending on if this is a copy or move.dragExit: This event is triggered on the target destination List if the item leaves the List without dropping an item. The event handler hides the feedback icon.
dragDrop: This event is triggered on the target destination List when an item is dropped over the List. This event adds the item to the list and hides the feedback icon.
dragComplete: This event is triggered on the initiating List. The event handler removes the item from the list if the drag was a move.
In the sample that I’m providing, I have two Lists. The first List includes the name of a guest and a number of people attending in their group. You should be able to drag items from the first List to the second List until the total number of people “attending” in the second list is greater than 5. In the code, I am increasing the value of a global variable “totalGuests” whenever an item is added to the second list. In the custom dragDrop handler for this second List, the value of totalGuests is checked. If this value is greater than 5, then, the drag is cancelled.
Sample code: dragExample.mxml