Handling mandatory fields with form clear - Angular
Clash Royale CLAN TAG#URR8PPP
Handling mandatory fields with form clear - Angular
Form containing bunch of required fields are their, Here I am able to handle all validations and error messages perfectly. But when I clear the form, now error messaging displaying for mandatory filed's like "Field is mandatory".
Here my expected behavior is when clear the form just form comes to the initial stage and not to validate any field.
I'm not getting any idea to handle this, So any idea or any suggestion is helpful for me. Thanks in advance.
Present I am using Reactive form and through generic validater to handle validations like below.
processMessages(container: FormGroup): [key: string]: string
let messages = ;
for (let controlKey in container.controls)
if (container.controls.hasOwnProperty(controlKey))
let c = container.controls[controlKey];
// If it is a FormGroup, process its child controls.
if (c instanceof FormGroup)
let childMessages = this.processMessages(c);
Object.assign(messages, childMessages);
else
// Only validate if there are validation messages for the control
if (this.validationMessages[controlKey])
messages[controlKey] = '';
if ((c.dirty
return messages;
What type of form are you using ? If reactive form then while showing validation feedback .. use <formcontrol>.touched && <formcontrol>.errors. in *ngIf as a condition.
– Shubham Yerawar
7 mins ago
@Chellappan updated
– Royal
1 min ago
@ShubhamYerawar Yes using Reactive forms and updated validation code as well.
– Royal
8 secs ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
can you share your code
– Chellappan
10 mins ago