When dragging, if currently dragged element is over a (fixed) non-movable element, it should do some checking to find the closest available element to be swapped with. After that I would like to cancel the dragging even if mouse button is not released.
How to programmatically cancel the dragging when some condition is met in the move
event ?
<draggable
:list="fields"
item-key="id"
handle=".draggable"
:move="draggableOnMove"
>
// template
</draggable>
const draggableOnMove = (e: any) => {
const context = e.draggedContext;
const related = e.relatedContext;
// Disallow to move the fixed element
if (related.element.value?.fixed) {
// Swap with closest non fixed element
let swappableIndex = context.futureIndex + 1;
while (fields.value[swappableIndex].value?.fixed) {
swappableIndex++;
}
fieldsComposable.swap(context.index, swappableIndex);
// how to cancel a dragging here after elements has been swapped manually <----
};
};
beforeMove
event to check your condition and set the cancel flag if necessary.move
event, check the cancel flag, and if it's set, prevent further dragging.Here's how you can implement this in your code: