This repository has been archived by the owner on Jul 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Validation Callback
Ghislain B edited this page Mar 23, 2017
·
6 revisions
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.
<!-- 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()" />
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
Contents
- Angular-Validation Wiki
- Installation
- Demo
- Code Samples
- Functionalities
- Custom Validations
- Properties & Options
- Validators
- Tests
- Misc