javascript - Form $setValidity back to true not working -


i set form validate on server side onblur event. server-side validation working fine , returning errors expected. however, once set validity false field, setting true not removing $error messages. isn't $setvalidity true supposed remove errors form?

this controller:

angular.module('artists').controller('artistscontroller', ['$scope', '$stateparams', '$location', 'authentication', 'artists',   function($scope, $stateparams, $location, authentication, artists) {     $scope.authentication = authentication;      $scope.processform = function(val){          var artist = new artists({             name: $scope.artistform.name.$viewvalue,             quote: $scope.artistform.quote.$viewvalue         });         artist.$save(function(response) {           $scope.artistform.$setvalidity(val,true);         }, function(errorresponse) {           if(val in errorresponse.data){             $scope.artistform.$setvalidity(val,false,errorresponse.data[val].message);           }else{             $scope.artistform.$setvalidity(val,true);           }         });      };  }]); 

in case field set normal, when edit it. happens because $scope loaded different controller , not applied. therefore, need use $apply

$scope.$apply(function(){      $scope.artistform.$setvalidity(val,true); }) 

here's docs: https://docs.angularjs.org/api/ng/type/$rootscope.scope


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -