diff --git a/dmp-frontend/src/app/form/fields/dynamic-form-field.component.ts b/dmp-frontend/src/app/form/fields/dynamic-form-field.component.ts index 58d0537ff..ffdbcdad1 100644 --- a/dmp-frontend/src/app/form/fields/dynamic-form-field.component.ts +++ b/dmp-frontend/src/app/form/fields/dynamic-form-field.component.ts @@ -69,6 +69,8 @@ export class DynamicFormFieldComponent { this.AddvalidationRules(rule._target); } else { this.dataModel.getFieldByKey(rule._target).visible = false; + this.form.controls[rule._target].clearValidators(); // when a field is hidden must clear the validators and the errors + this.form.controls[rule._target].updateValueAndValidity(); } } if (rule._ruleStyle == "checked") { //checkbox field @@ -77,6 +79,8 @@ export class DynamicFormFieldComponent { this.AddvalidationRules(rule._target); } else { this.dataModel.getFieldByKey(rule._target).visible = false; + this.form.controls[rule._target].clearValidators(); + this.form.controls[rule._target].updateValueAndValidity(); } } if (rule._ruleStyle == "existence") { @@ -85,6 +89,8 @@ export class DynamicFormFieldComponent { this.AddvalidationRules(rule._target); } else { this.dataModel.getFieldByKey(rule._target).visible = false; + this.form.controls[rule._target].clearValidators(); + this.form.controls[rule._target].updateValueAndValidity(); } } if (rule._ruleStyle == "regex") { @@ -93,6 +99,8 @@ export class DynamicFormFieldComponent { this.AddvalidationRules(rule._target); } else { this.dataModel.getFieldByKey(rule._target).visible = false; + this.form.controls[rule._target].clearValidators(); + this.form.controls[rule._target].updateValueAndValidity(); } } } @@ -129,7 +137,7 @@ export class DynamicFormFieldComponent { }); this.form.controls[field].setValidators(arrayVal); //Multiple Validators, Usage of array because setValidator override any validators that are provided during initialistaion - + this.form.controls[field].updateValueAndValidity(); //hide--> visible must update the validators }