0

Is there any way to for example, click on submit button and then trigger all the validations of the form fields, noticed it shows error messages from beginning if not checking dirty or touched which is fine, but what if i don't have to show messages from the beginning ?

use case: for user to view all the fields that are missing or wrong before submitting data

1 Answer 1

1

You can do this:

<form novalidate (submit)="submit(loginForm)">

   <input type="email" formControlName="email">

   <p *ngIf="loginForm.get('email').hasError('required') && submitted">This field is required</p>

   <button type="submit" class="btn btn-info">Submit</button>

</form>

And in your component:

submit( form : FormGroup ) {
   this.submitted = true;
   if( form.invalid ) return;
}
Sign up to request clarification or add additional context in comments.

1 Comment

yeah that approach works but thought there was a method to fire all the validations

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.