I have an angular directive used as attribute for validating the input.
Input looks like this (jade)
input.form-control(type='text', name='subjectinput', id='subjectinput', subjectid-noprefix-validator='(subject.nosuffix==1)')
and validator looks like
.directive('subjectidNoprefixValidator', function () {
return {
require: ['^form', 'ngModel'],
scope: {
noprefixformat: '=subjectidNoprefixValidator'
},
link: function (scope, element, attrs, ctrls) {
scope.form = ctrls[0]; // so we can use form reference in displaying error messages
var ngModel = ctrls[1];
ngModel.$validators.subjectidnoprefix = function (value) {
var status = true;
// removed some logic that sets status true or false
// using $scope.noprefixformat parameter
return status;
};
}
};
});
It works fine. However, sometimes in page actions an event happens that need validation to be re-triggered on the INPUT without touching it; some radio button alteration should re-trigger it and refresh validation status (as you see, my validator has a parameter).
I tried to achieve it by calling in page Controller
$scope.subjCreationForm.subjectinput.$validate();
but it does not seem to work. What could be the case and is there another way to trigger validation of a field programmatically when it employs $validators?