validation - How to validate an AngularJS directive that contains selects? -
i created directive made 2 selects, loads options 2 json file:
http://plnkr.co/edit/7kk66c?p=preview
as can see works fine, put directive form, , check validity. more specific directive valid if user selected option both selects (just both have been marked required). found fields of tutorial how set validy of directive contains input text, nothing check on selects...how that?
have @ templatedir.html on this plunker solution.
you need to:
- add
<form></form>
wrappername="..."
attribute. - add
ng-model="..."
attribute each of<select></select>
tags. - add
ng-required="true"
each of<select></select>
tags.
you can check whether or not form in valid state using formname.$invalid
.
the ng-model
tells angular bind values of inputs variable name specify in model , ng-required
tells angular 2 inputs must completed. i'm assuming purpose of <form></form>
obvious. :)
Comments
Post a Comment