javascript - AngularJS form $valid set to true before validation completes -


i displaying validation symbol in left nav of page indicate whether form valid or not. when load page form's $valid attribute set true, changes false (as should given retrieved input data). result validation symbol flickering valid invalid. there way prevent this? validation symbol tied valid attribute on $scope, gets set within watch. there logic added watch check if form hasn't finished initializing or validating? thanks!

here current watch code. valid attribute goes undefined true false after couple different watch cycles.

$scope.$watch( 'sections.' + section.sectionname + '.sectionform.$valid', function( valid ) {     section.valid = valid; }, true); 

and html display validation symbol:

<span ng-class="{ 'fa fa-check': section.valid,     'fa fa-warning': !section.valid}"> </span> 

i think problem $watch function. first time set "section.valid" undefined. don't need watch manually. each form directive creates instance of formcontroller. so, can check form validity directly in view.

<span ng-class="{'fa fa-check': sectionformname.$valid, 'fa fa-warning': sectionformname.$invalid}"></span> 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -