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> wrapper name="..." 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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -