Answer the question
In order to leave comments, you need to log in
How to cancel server validation error in angular?
I put validation errors from the server into the form like this:
$scope.form.$setValidity(fld, false);
$scope.form[fld].$dirty = true;
$scope.form[fld].$error.backendError = err;
Answer the question
In order to leave comments, you need to log in
Some crap.
.directive('inpWatched', function() {
return {
link: function(scope, iElem, iAttrs) {
var myname = iAttrs.name;
scope.$watch(function() { return iElem.hasClass('ng-dirty'); },
function(val) {
delete scope.form[myname].$error.backendError;
});
}
};
})
It is logical to assume that at the moment of pressing the "Submit" button, we accept the entered data as the starting point for the further process, therefore I would set $dirty = false to all fields. After we received errors from the server, we put them down in acc. inputs, we mark the server invalidity.
As soon as the user changes an invalid field, it becomes $dirty, which tells us that server-side invalidation can be removed from this field.
It works like this for me.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question