Giter Site home page Giter Site logo

Comments (1)

NumericFactory avatar NumericFactory commented on May 17, 2024

Ok i found solutions and i give you this one !

1 ngx-dnd events

ngx-dnd library allows us to use many events : drop(), drag(), over(), out(), remove(), cancel()

https://github.com/swimlane/ngx-dnd/blob/master/src/directives/ngx-droppable.directive.ts#L36

So, you can call your own method in your component if an item is "dropped". Example :

in your form.component.html

<div (drop)="dropped($event)" 
     class="ngx-dnd-container" 
     ngxDroppable 
     [model]="formData.controls">
//...

in your form.component.ts

dropped(event) {
    alert('Ok drop is Donne !')
}

2 Update formArray
The problem was here : our "drop action" didn't re-order the formArray
Angualar formArray class expose many methods to solve this problem
https://angular.io/api/forms/FormArray

I choise the reset() method cause we can pass value in parameters and update the entire formArray.

reset(value?: any, options?: Object)

Finally, update your méthod in your form.component.ts

dropped(event) {
    let linesCopy = [];
    this.lines = this.form.get('lines') as FormArray;
    for(let line of this.lines.controls) {
        linesCopy.push(line.value);
    }
    console.log(linesCopy);
    console.log(this.lines.value);
    this.lines.reset(linesCopy);
}

Oh It works correctly now ! You can check here =>
https://angular-xqhjug.stackblitz.io

PS: Be careful to use only form class methods when you manipulate forms in Angular. Dont'use JS methods to push, remove, set value, etc...
formArray Class => https://angular.io/api/forms/FormArray

Frederic LOSSIGNOL, leadDev from Paris, France

from ngx-dnd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.