M
M
Maxim Vasiliev2014-12-03 23:47:50
Angular
Maxim Vasiliev, 2014-12-03 23:47:50

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;

Once the user recognizes these errors and changes the field, the server-side validation error obviously becomes invalid and should be removed.
How and what form properties to watch for this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Vasiliev, 2014-12-04
@qmax

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;
                             });
            }
        };
    })

_
_ _, 2014-12-03
@AMar4enko

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 question

Ask a Question

731 491 924 answers to any question