3

I was trying to follow advice from this link to revert the drop action:

Dragula :revert drop in ng2-dragula

but with no success.

What i want to do is to be able to revert the drag operation under certain conditions. Alternatively on condition disable Dragula altogether.

Html:

.ts file

    export class VisibilityConfiguratorComponent implements OnChanges {

      colsCopy: ColumnItem[];

      constructor(private dragulaService: DragulaService) {
        let drake = dragulaService.drop.subscribe((value) => {
          this.applyConfig();
        });
      }

      ngOnInit() {
        this.dragulaService.setOptions('bag', { moves: (el, container, handle) => { return false; } });
  }
}

As you can see I'm trying to disable move entirely but this doesn't seem to have any effect.

Community
  • 1
  • 1
cah1r
  • 1,751
  • 6
  • 28
  • 47
  • 1
    Are you sure you need moves option? Maybe accepts option will be more relevant? https://github.com/bevacqua/dragula#optionsaccepts – NtsDK Sep 20 '17 at 22:04

1 Answers1

3

You can use this method for cancel the drag operation under your condition:

if( yourCondition )
  this.dragulaService.find('yourBagName').drake.cancel(true)

Whats happening in your cancel event is based on your bag options, i use this one:

this.dragulaService.setOptions('yourBagName', {
  revertOnSpill: true
});

If this option is setted to your bag, the cancel event will revert your drag operation. More options here: https://github.com/bevacqua/dragula#dragulacontainers-options

  • Sory your solution is not working for me. Besides I don't want to revertOnSpill but not allow the user to drag elements on special condition at all. When the condition changes the user should be able to drag elements. – cah1r Apr 19 '17 at 08:01
  • I didnt use the revertOnSpill. but I was able to prevent the drag on specific conditions using the drake.cancel(true). Thanks! – Abdul K Shahid May 06 '21 at 11:01