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

Drop to predefined columns? #574

Closed malinga91 closed 3 years ago

malinga91 commented 5 years ago

I'm working on a form builder. Drag & drop done using Dragular. Questions are predefined and <app-question [question]="question"></app-question> handle the question.

Form Builder

rowsList = [
  {
    "columns": [
      { question : column_two},
      { another_question : column_three },
  {
    "columns": [
      {},
      {},
      {}
    ]
  }
]

COMPONENT.HTML

<div [dragula]="'bag'" [dragulaModel]="rowsList">
    <div *ngFor="let row of rowsList; let i = index;">
      <div class="form-row" [dragula]="'bag2'" [dragulaModel]="row.columns">

        <div class="col test" *ngFor="let question of row.columns">
          <ng-container *ngIf="question.label">
            <app-question [question]="question"></app-question>
          </ng-container>
        </div>

      </div>
    </div>
  </div>

COMPONENT.TS

 this.dragulaService.setOptions('bag', {
      invalid: function (el, handle) {
        return (el.className == "col");
      }
    });

this.dragulaService.setOptions('bag2', {
      accepts: function (el, target, source, sibling) {
            return target.className === 'col'
       }
    })