1
I have the following directive:
.directive('validateCPF', function () {
return {
require: 'ngModel',
link: function (scope, element, attrs, ctrl) {
ctrl.$validators.cpf = function (modelValue, viewValue) {
console.log('chamou directiva');
var validatorCPF = new CPF();
return (validatorCPF.valida(viewValue));
};
}
};
});
This directive uses an external lib to validate the cpf
, but it does not even reach the console.log
.
My form:
<input id="cpf" class="col-xs-12 cpf" type="text" name="cpf" ng-model="cau.cpf" validate-CPF >
Angularjs version 1.4
I liked the idea of Blur, but I will validate in the function in the directive if viewModel is defined. in this case only after losing focus, in the same way as with Blur...
– Luiz Fernando Dubiela
A yes, at your discretion. I only mentioned it as an alternative. = D
– celsomtrindade