Reputation: 289
How to determine that a Angular form is tried to submit or not by user to show some invalid fields information only when he attempted to do submission.
Upvotes: 2
Views: 68
Reputation: 1052
When you create a form in angular, then the form object contains a boolian property "submitted". It becomes true when user tries to submit a form.
<form #searchForm="ngForm" [ngClass]="{'FormTried':searchForm.submitted}"
(ngSubmit)="submitData(searchForm)" >
// your form fields
</form>
I used it to add a class for form tried to submit or not.
Upvotes: 4
Reputation: 75
<form #empForm="ngForm" [ngClass]="{'FormTried':empForm._submitted}"
(ngSubmit)="submitData(empForm)" >
// added code here
</form>
I have used this and this works fine at my end, please try this also.
Upvotes: 0