diff --git a/src/app/shared/form/form.service.ts b/src/app/shared/form/form.service.ts index 9356f86e8cf5faadc1c0c69cf0260f670a6ef277..ee354d504fef10570e802583e5147c1858b6ea5c 100644 --- a/src/app/shared/form/form.service.ts +++ b/src/app/shared/form/form.service.ts @@ -1,6 +1,6 @@ import { map, distinctUntilChanged, filter } from 'rxjs/operators'; import { Inject, Injectable } from '@angular/core'; -import { AbstractControl, FormControl, FormGroup } from '@angular/forms'; +import { AbstractControl, FormArray, FormControl, FormGroup } from '@angular/forms'; import { Observable } from 'rxjs'; import { select, Store } from '@ngrx/store'; @@ -82,12 +82,13 @@ export class FormService { /** * Method to validate form's fields */ - public validateAllFormFields(formGroup: FormGroup) { + public validateAllFormFields(formGroup: FormGroup | FormArray) { Object.keys(formGroup.controls).forEach((field) => { const control = formGroup.get(field); if (control instanceof FormControl) { control.markAsTouched({ onlySelf: true }); - } else if (control instanceof FormGroup) { + control.markAsDirty({ onlySelf: true }); + } else if (control instanceof FormGroup || control instanceof FormArray) { this.validateAllFormFields(control); } }); diff --git a/src/app/shared/mocks/mock-form-service.ts b/src/app/shared/mocks/mock-form-service.ts index 31455f03da81adb61156e6ad6f0fb6b38a817402..bae76eb69f69325250195f0d0144661d3b0e7c22 100644 --- a/src/app/shared/mocks/mock-form-service.ts +++ b/src/app/shared/mocks/mock-form-service.ts @@ -12,8 +12,8 @@ export function getMockFormService( getForm: observableOf({}), getUniqueId: id$, resetForm: {}, - validateAllFormFields: {}, - isValid: observableOf(true), + validateAllFormFields: jasmine.createSpy('validateAllFormFields'), + isValid: jasmine.createSpy('isValid'), isFormInitialized: observableOf(true) });