angulardrag-and-dropionic3dragulang2-dragula

Ng-Dragula and drop more detailed constraints


I'm developing an app using Ionic 3 and Angular 4 frameworks and Ng-Dragula library.

I need more detailed control over drag and drop of elements provided by Ng-Dragula.

For example, I have three columns.

I want the user can move itens:

I don't want user can move itens:

How can I set this detailed constraints?


Solution

  • You can set options on each container (each column), containing an 'accepts' function that determines whether a particular item can be dropped on a particular container, in a particular position.

    For example,

    dragulaService.setOptions('column-1', {
          accepts: function(el, target, source, sibling) {
              // return true to allow drop, false to disallow
          }
        })
    

    According to the documentation at https://github.com/bevacqua/dragula#optionsaccepts, the arguments to this function are:

    You would return true to allow the drop, false to prevent it.