I've defined a validator by following the documentation under Custom Validation at https://docs.angularjs.org/guide/forms. But for some reason the link
function isn't getting called. I can tell it's not getting called because the log message doesn't appear.
HTML
<textarea name="topic1Data" ng-model="inputCtrl.inputValues.topic1Data" rows="10" cols="30" required hasHeaders></textarea>
JavaScript
inputForm.directive('hasHeaders', function() {
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
console.log("Evaluating hasAtLeastAHeaderRow validator");
ctrl.$validators.integer = function(modelValue, viewValue) {
if (ctrl.$isEmpty(modelValue)) {
// consider empty models to be valid
return true;
}
if (INTEGER_REGEXP.test(viewValue)) {
// it is valid
return true;
}
// it is invalid
return false;
};
}
};
});
Others have reported the same symptom but the cause of my problem seems to be different:
What am I doing wrong?