I set up a form to validate on the server side OnBlur event. The server-side validation is working fine and returning errors as expected. However, once I set validity to false
for a field, setting it back to true
is not removing the $error messages. Isn't $setValidity true supposed to remove errors from form?
This is the 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);
}
});
};
}]);