I have a registration form validating client-side that works fine. My app has also a server-side validation which returns the client a JSON with errors for each field.
I try to handle them like this:
// errors = {
// "username": [
// "Account 'test2@test.com' already exist!"
// ]
// };
for(var field in errors) {
$scope.RegForm.$setValidity(field, false);
$scope.RegForm[field].$error.server = errors[field].join('\n');
}
The problem is that errors remain visible even when I change field. I need to set validity back to true, and remove server error at some moment. Just not sure how and when.
How to properly treat server data in order to make them change? $asyncValidators will not work, because in the case of username field I'm not allowed to register user, just to see if such username is free.