From f26be6fc7a56c4b4b9a465d0f3fd5d605b28f5e3 Mon Sep 17 00:00:00 2001 From: pbardy2000 <146740183+pbardy2000@users.noreply.github.com> Date: Wed, 3 Jan 2024 15:32:42 +0000 Subject: [PATCH] fix(cb2-10321): ensure validation is run only when control is visible (#1346) --- src/app/forms/templates/general/adr.template.ts | 1 - src/app/forms/validators/custom-validators.ts | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/forms/templates/general/adr.template.ts b/src/app/forms/templates/general/adr.template.ts index f7e12848d..5e4584973 100644 --- a/src/app/forms/templates/general/adr.template.ts +++ b/src/app/forms/templates/general/adr.template.ts @@ -723,7 +723,6 @@ export const AdrTemplate: FormNode = { name: ValidatorNames.RequiredIfNotHidden, }, ], - }, { name: 'techRecord_adrDetails_declarationsSeen', diff --git a/src/app/forms/validators/custom-validators.ts b/src/app/forms/validators/custom-validators.ts index 7ac66e1c6..a94ef2738 100644 --- a/src/app/forms/validators/custom-validators.ts +++ b/src/app/forms/validators/custom-validators.ts @@ -235,6 +235,7 @@ export class CustomValidators { }; static dateIsInvalid: ValidatorFn = (control: AbstractControl): ValidationErrors | null => { + if (control instanceof CustomFormControl && control.meta.hide) return null; const [yyyy, mm, dd] = (control.value ?? '').split('-'); const label = control instanceof CustomFormControl ? control.meta.label : undefined; const checks = validateDate(parseInt(dd ?? '', 10), parseInt(mm ?? '', 10), parseInt(yyyy ?? '', 10), label);