Ravi Kant
Ravi Kant

Reputation: 289

How to determine that a Angular form is tried to submit or not

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

Answers (2)

mukund patel
mukund patel

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

TOSHASHU123
TOSHASHU123

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

Related Questions