Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. productArrayForm = this.fb.group({
  2. arrayRoot: this.fb.array([this.prodGroup])
  3. })
  4. get arrayRoot(){
  5. return this.productArrayForm.get('arrayRoot') as FormArray;
  6. }
  7. get prodGroup(): FormGroup {
  8. return this.fb.group ({
  9. array:this.fb.array([])
  10. })
  11. }
  12. get prodArray() {
  13. return this.prodGroup.get('array') as FormArray;
  14. }
  15. addOption() {
  16. this.productList.push(this.productListGroup);
  17. }
  18. checkProd(product: string, isChecked: boolean) {
  19. if (isChecked){
  20. this.prodArray.push(new FormControl(product));
  21. }
  22. }
  23.  
  24. <form class='mb-2' [formGroup]='productArrayForm'>
  25. <div formArrayName="arrayRoot">
  26. <div *ngFor="let li of arrayRoot.controls; let j = index" [formGroupName]='j'>
  27. <div class="d-flex justify-content-end">
  28. <button (click)='addOption()'>+</button>
  29. <div class="form-group">
  30. <div class="form-control" *ngFor="let product of productsLocal;">
  31. <input type="checkbox" (change)='checkProd(product.ProductId, $event.target.checked)'> {{product.ProductName}}
  32. </div>
  33. </div>
  34. </div>
  35. </div>
  36. </form>`
  37.  
  38. <form role="form" (ngSubmit)="f.form.valid && onSubmit()" #f="ngForm" novalidate>
  39. <div *ngFor="let item of allSaleItems; index as saleIndex">
  40. <select *ngIf="!item.batch" class="form-control font-12 p-l-0 p-r-0"
  41. [name]="'selectBatch' + saleIndex" [(ngModel)]="item.selectBatch" (change)="batchChange(item)"
  42. [ngClass]="{ 'is-invalid': f.submitted && !item.selectBatch }">
  43. <option value="" disabled>Product Batch Here</option>
  44. <option *ngFor="let pBatch of item.productBatches" [ngValue]="pBatch">{{pBatch.batch_details}}</option>
  45. </select>
  46. <div *ngIf="f.submitted && !item.selectBatch" class="invalid-feedback">
  47. Product batch is required
  48. </div>
  49. </div>
  50. <button type="submit">save</button>
  51. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement