import { Component } from '@angular/core'; import { FormArray, FormBuilder, FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators } from "@angular/forms"; import {NzColDirective} from "ng-zorro-antd/grid"; import {NzFlexDirective} from "ng-zorro-antd/flex"; import {NzFormControlComponent, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form"; import {NzInputDirective} from "ng-zorro-antd/input"; import {NzInputNumberComponent} from "ng-zorro-antd/input-number"; import {NzTableComponent} from "ng-zorro-antd/table"; import {GetProductDto} from "../../services/api"; @Component({ selector: 'app-create-quotation-form', imports: [ FormsModule, NzColDirective, NzFlexDirective, NzFormControlComponent, NzFormItemComponent, NzFormLabelComponent, NzInputDirective, NzInputNumberComponent, NzTableComponent, ReactiveFormsModule ], templateUrl: './create-quotation-form.html', styleUrl: './create-quotation-form.css', }) export class CreateQuotationForm { createQuotationForm: FormGroup constructor(private fb: FormBuilder) { this.createQuotationForm = this.fb.group({ message: new FormControl(null, Validators.required), purchaseConditions: new FormControl(null, Validators.required), lines: this.fb.array([]) }); } get lines(): FormArray { return this.createQuotationForm.get('lines') as FormArray; } // Ajouter des produits sélectionnés dans le formulaire syncSelectedProducts(selectedProducts: GetProductDto[]) { this.lines.clear(); selectedProducts.forEach(p => { this.lines.push(this.fb.group({ productId: [p.id], name: [p.name], quantity: [1, [Validators.required, Validators.min(1)]] })); }); } }