Navaneet
Navaneet

Reputation: 1387

Check form is modified for certain inputs

I have a form with some tabs.Each tabs has set of some controls which are binded using angularjs and has ng-model .I want to check whether user has entered or modified any data in a particular tab during submit.

myForm.$dirty will check whether user has interacted with the form. But I need to check controls are filled in particular tabs and give some appropriate messages . So can i check angularjs watch or ng-dirty for each controls and verify that user has modified data. Is there any other good solution for the same?

Upvotes: 0

Views: 458

Answers (1)

In angularjs you can make very different validations when using forms and classes like ng-dirty and ng-touched.

This way u can check wether determined control has been modified.

    ng-dirty: the control has been interacted with

    ng-touched: the control has been blurred

Also you can check validity or other similar things.

U have all the docs at:

https://docs.angularjs.org/guide/forms

Anyway, you can also check this with the FormController

https://docs.angularjs.org/api/ng/type/form.FormController

And then show the messages with angular directives for bootstrap (see Modals)

https://angular-ui.github.io/bootstrap/

As you say, you have different controls and you need to show different messages depending on the control and on the user´s input. Then I think the way you musts code it, is by looking for ng-dirty or ng-touched

There you have an example about how using it: http://www.w3schools.com/angular/angular_validation.asp

Hope it can help!!

Upvotes: 2

Related Questions