Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- productArrayForm = this.fb.group({
- arrayRoot: this.fb.array([this.prodGroup])
- })
- get arrayRoot(){
- return this.productArrayForm.get('arrayRoot') as FormArray;
- }
- get prodGroup(): FormGroup {
- return this.fb.group ({
- array:this.fb.array([])
- })
- }
- get prodArray() {
- return this.prodGroup.get('array') as FormArray;
- }
- addOption() {
- this.productList.push(this.productListGroup);
- }
- checkProd(product: string, isChecked: boolean) {
- if (isChecked){
- this.prodArray.push(new FormControl(product));
- }
- }
- <form class='mb-2' [formGroup]='productArrayForm'>
- <div formArrayName="arrayRoot">
- <div *ngFor="let li of arrayRoot.controls; let j = index" [formGroupName]='j'>
- <div class="d-flex justify-content-end">
- <button (click)='addOption()'>+</button>
- <div class="form-group">
- <div class="form-control" *ngFor="let product of productsLocal;">
- <input type="checkbox" (change)='checkProd(product.ProductId, $event.target.checked)'> {{product.ProductName}}
- </div>
- </div>
- </div>
- </div>
- </form>`
- <form role="form" (ngSubmit)="f.form.valid && onSubmit()" #f="ngForm" novalidate>
- <div *ngFor="let item of allSaleItems; index as saleIndex">
- <select *ngIf="!item.batch" class="form-control font-12 p-l-0 p-r-0"
- [name]="'selectBatch' + saleIndex" [(ngModel)]="item.selectBatch" (change)="batchChange(item)"
- [ngClass]="{ 'is-invalid': f.submitted && !item.selectBatch }">
- <option value="" disabled>Product Batch Here</option>
- <option *ngFor="let pBatch of item.productBatches" [ngValue]="pBatch">{{pBatch.batch_details}}</option>
- </select>
- <div *ngIf="f.submitted && !item.selectBatch" class="invalid-feedback">
- Product batch is required
- </div>
- </div>
- <button type="submit">save</button>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement