bevacqua / dragula

:ok_hand: Drag and drop so simple it hurts
https://bevacqua.github.io/dragula/
MIT License
21.89k stars 1.97k forks source link

When using Copy, removeonspill is not working, is there a workaround? #668

Open Ometecuthli opened 3 years ago

Ometecuthli commented 3 years ago

As the title says, we need to make a COPY but when we enable this option, the removeOnSpill option is automatically disabled. Is there any workaround that works?

I have two divs. Right is a menu with options that should be able to be dragged to the left. From the left to the right dragging should be disabled because I do not want to have duplicated in the right menu. But when an item from the left is dragged outside of both the left and right div, then it should be removed from the left div.

Hope someone can help me out.

My current code:

let lastElement = undefined;
const drake = dragula({
    containers: [document.querySelector('#right'), document.querySelector('#left')],
    copy: true,
    copySortSource: true,
});

drake.on('drop', (el, target, source, sibling) => {
    if (target === null || target.getAttribute('id') === null) {
        drake.cancel(true);
        return false;
    }

    if (target.getAttribute('id') === 'right') {
        drake.cancel(true);
        return false;
    }

    return true;
});
onliniak commented 2 years ago

Check out example. https://jsfiddle.net/qmeu8j4y/1/

Hope I helped