As a beginner in angular 6, I am currently facing an issue with resetting a form after submitting data.
Although everything seems to be functioning properly, when I reset the form after successfully submitting data to the database, it triggers all the required validators in the form.
Despite trying numerous approaches to resolve this, I have been unsuccessful in finding a solution.
My goal is to reset the form and all validators after each submission, before entering new data into the form fields for another submission.
Snippet from app.component.html:
<form [formGroup]="newMemberForm" (submit)="CreateMember(newMemberForm.value)" novalidate>
....
....
</form>
Snippet from app.component.ts:
this.newMemberForm = this.formBuilder.group({
M_Number: ['', [Validators.required]],
F_Number: ['', [Validators.required]],
M_Name: ['', [Validators.required, Validators.minLength(4)]],
M_Status: ['', [Validators.required]],
M_Dob: ['', [Validators.required]],
M_Sex: ['', [Validators.required]],
});
CreateMember(memberForm) {
this.dmlService.CreateNewMember(memberForm).subscribe(data => {
if (data[0]['RESPONSE'] == 'TRUE')
{
this.newMemberForm.reset();
}
});
}
Even after resetting the form, the required validators are triggered. If I remove all the validators within the function above, the validations do not work when entering new form data.
I am seeking assistance in completely resetting all validators and the form after each submission, allowing me to submit the next set of form data smoothly.
If anyone could provide guidance on how to solve this issue, it would be greatly appreciated.