After implementing server-side validation using the OnBlur event in a form, I encountered an issue where setting the validity of a field to false
does not remove the error messages even after setting it back to true
. I expected $setValidity true to clear errors from the form. Is there something wrong with my implementation?
Here is the code snippet from 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);
}
});
};
}]);