Validation Callback - ghiscoding/angular-validation GitHub Wiki
Since version 1.4.14
Validation Callback are useful when you want to run extra piece of code but only after the Validation is over.
Oh but wait a minute...
- But why do we need that?
- Shouldn't the Validation be super fast anyway?
The answer is yes but no. The validation when it runs is indeed super fast but the problem is that Angular-Validation has a debounce of 1 sec by default. The debounce basically waits for the user inactivity before doing any kind of validation. So the validation-callback will help dealing with this problem.
Internally the validation-callback is connected to a promise, it basically resolves whenever the validation is finished.
Directive
<!-- defining the callback function call by using `validation-callback` -->
<input type="text" class="form-control"
name="firstname"
ng-model="vm.user.firstname"
validation="required"
validation-callback="vm.myCallbackFunction()" />
Callback
myApp.controller('ctrlDirective', [function () {
var vm = this;
vm.myCallbackFunction = function() {
var isFormValid = vm.form1.$valid;
if(isFormValid) {
vm.fullName = vm.firstName + ' ' + vm.lastName;
}
}
}]);
For a complete test case example, you could also look at my code sample in the folder more-examples/validationCallback