From 148732b41a48ddf75f414a57875e37b3b8cb1b4c Mon Sep 17 00:00:00 2001 From: "alejandro.bulgaris@qcif.edu.au" Date: Mon, 23 Oct 2023 03:30:34 +0000 Subject: [PATCH] Fixed validators that become enabled when made visible even when the field isn't configured to be required --- .../shared/form/field-contributor.component.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/angular-legacy/shared/form/field-contributor.component.ts b/angular-legacy/shared/form/field-contributor.component.ts index 2da7dd73ab..1f99e7b591 100644 --- a/angular-legacy/shared/form/field-contributor.component.ts +++ b/angular-legacy/shared/form/field-contributor.component.ts @@ -217,8 +217,6 @@ export class ContributorField extends FieldBase implements CustomValidation if (this.required) { this.enableValidators(); } else { - // disable the validators otherwise they'll get enabled on show/hide - this.validators = {}; // if splitting names, attach handler to individual input form control if (this.splitNames) { const reqFields = ['family_name', 'given_name']; @@ -532,15 +530,17 @@ export class ContributorField extends FieldBase implements CustomValidation if (!that.visible) { // restore validators if (that.formModel) { + if (that.required) { if(that['enableValidators'] != null && typeof(that['enableValidators']) == 'function') { that['enableValidators'](); } else { that.formModel.setValidators(that.validators); } - setTimeout(() => { - that.setValue(that.formModel.value,false,true) - }); - that.formModel.updateValueAndValidity(); + } + setTimeout(() => { + that.setValue(that.formModel.value,false,true) + }); + that.formModel.updateValueAndValidity(); } } }