I have to stop the drag async after the drag is started. Can I add something in drag event to cancel the drag ?
document.querySelector('#drag-elem').addEventListener('drag', function(e){
// Stop the drag
e.preventDefault();
})
document.querySelector('#drag-elem').addEventListener('dragstart', function(e){
console.log('dragstart')
})
<div draggable='true' id='drag-elem'>Draggable</div>
You can use a
dataIsValidflag to decide if the drop is allowed in both theondragoverandondropevent handlers. Here is an example where the data is random number between 0 and 1, which is considered valid when larger than 0.5, and the asynchronous validation takes one whole second. Try dragging the Source over the Target and wait for at least one second before releasing the left mouse button.