Comments (1)
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)
- Transitive license is not valid since [email protected] has no license text HOT 1
- element should be orderable even if it has copy = true
- Previous and Current Container - Dropzone
- Documentation - Demo URL is 404
- Release with support for Angular 11 HOT 2
- multiple drop happening in dynamically created ngx-dnd-contianer (s) (used ngFor iteration)-stackblitz URL added
- Angular 12 Upgrade HOT 1
- Handle shadow dom HOT 1
- A11y Drag and Drop
- ngxDraggable onDrag event not calling
- ngxDragHandle not working with Angular 12 HOT 1
- Angular 12 Upgrade Release (PR already exists) HOT 5
- [Bug] Having a draggable element with `display: inline-block` inside a droppable container will disable dragging.
- Angular 13 Upgrade Release HOT 31
- [Help] Would you please update the builder demo by adding the restrictions (dropzone/s for ngx-dnd-container and ngx-dnd-item).
- [moves]="false"or [moves]="Any()" giving build time error if in tsconfig using ->"strictTemplates": true in angular 13. error "error TS2322: Type 'boolean' is not assignable to type '(model: any, source: any, handle: any, sibling: any) => boolean'."
- Version 6 is not compatible with Angular 10 and Ivy
- How to assign the dropzones to ngx-dnd-items when we are assigning model to the ngx-dnd-container
- Could we release an Ivy version to npm based on tag 9.1.0? HOT 6
- Is there any update for Angular16? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngx-dnd.