clear validators and delete errors after hiding the field
This commit is contained in:
parent
8c44b7c128
commit
bc21e8f6d5
|
@ -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
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue