Open robfletcher opened 12 years ago
This can be done in a controller with a call such as
$scope.form.title.$setValidity('unique', false);
The problem is that the validity state needs to be recomputed after the user changes the form value.
Directive to clear errors when the user changes the form value. If by "recomputed" you mean actually re-submit to the server then try this answer instead of mine: http://stackoverflow.com/questions/12864887/angularjs-integrating-with-server-side-validation
<input type="text" ... validated>
angular.module('serverSideValidation', []).directive('validated', function() {
return {
restrict: 'A',
require: '?ngModel',
link: function(scope, elem, attr, ctrl) {
if (attr.ngModel) {
scope.$watch(attr.ngModel, function(value) {
ctrl.$setValidity('unique', true); // <<< or whatever your error key is
});
}
}
};
});
See: [http://docs.angularjs.org/api/ng.directive:form]
Angular uses a different structure on the form controller field.$error.type, e.g.
title.$error.required
It would be nice to bind errors from server side validation to this structure so the display could work the same way for both.