Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dragula Copy and removeOnSpill

I'm trying to use the Dragula Drag & Drop library to Clone elements into a target container AND allow the user to remove cloned elements from the Target Container by drag & dropping them outside of the target container (spilling).

Using the examples provided I have this:

dragula([$('left-copy-1tomany'), $('right-copy-1tomany')], {
   copy: function (el, source) {
      return source === $('left-copy-1tomany');
   },
   accepts: function (el, target) {
      return target !== $('left-copy-1tomany');
   } 
});
dragula([$('right-copy-1tomany')], { removeOnSpill: true });

Which does not work - it seems that 'removeOnSpill' simply doesn't work if the container accepts a copy.

Does anybody know what I am not doing, doing wrong or if there is a work-around?

TIA!

like image 256
Serexx Avatar asked Nov 02 '15 22:11

Serexx


People also ask

How do I use Dragula?

dragula (containers?, options?) By default, dragula will allow the user to drag an element in any of the containers and drop it in any other container in the list. If the element is dropped anywhere that's not one of the containers, the event will be gracefully cancelled according to the revertOnSpill and removeOnSpill options.

What does Dragula return in Java?

The dragula method returns a tiny object with a concise API. We'll refer to the API returned by dragula as drake. This property contains the collection of containers that was passed to dragula when building this drake instance. You can push more containers and splice old containers at will.

How do I change the Order of items in a Dragula group?

Groups in Dragula are called bags: If you want the changes in order to be synced in your items array, simply use the dragulaModel directive with the name of the model. This way, when items are re-ordered via drag & drop, the items array will also have its items re-ordered to reflect the changes:

What are the CSS classes used in Dragula?

Dragula uses only four CSS classes. Their purpose is quickly explained below, but you can check dist/dragula.css to see the corresponding CSS rules. gu-unselectable is added to the mirrorContainer element when dragging. You can use it to style the mirrorContainer while something is being dragged.


1 Answers

I came here after looking for a while for a solution to a similar issue using the ng2-dragula for angular2.

    dragulaService.setOptions('wallet-bag', {
  removeOnSpill: (el: Element, source: Element): boolean => {
    return source.id === 'wallet';
  },
  copySortSource: false,
  copy: (el: Element, source: Element): boolean => {
    return source.id !== 'wallet';
  },
  accepts: (el: Element, target: Element, source: Element, sibling: Element): boolean => {
    return !el.contains(target) && target.id === 'wallet';
  }
});

I've got 4 divs that can all drag into one which has the id of wallet They are all part of the wallet-bag using this code, they can all copy into the wallet, not copy between each other, and you can remove them from the wallet using the spill but not from the others.

I'm posting my solution as it may also help someone.

like image 156
Nicholas Tsaoucis Avatar answered Oct 09 '22 02:10

Nicholas Tsaoucis