Skip to content
This repository was archived by the owner on Jan 24, 2019. It is now read-only.

Commit 1a63057

Browse files
committed
Update $pending object on async validations
When a custom validator returns a promise, uiValidation directive adds the validation key to ModelController's $pending object. When promise is resolve or rejected. $pending[key] is deleted automatically. This allow to use $pending variable from the view to show transient messages while validation is taking place.
1 parent e913d17 commit 1a63057

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

modules/validate/validate.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ angular.module('ui.validate',[]).directive('uiValidate', function () {
3535
var expression = scope.$eval(exprssn, { '$value' : valueToValidate });
3636
if (angular.isObject(expression) && angular.isFunction(expression.then)) {
3737
// expression is a promise
38+
if (angular.isUndefined(ctrl.$pending)) {
39+
ctrl.$pending = {};
40+
}
41+
// set pending state until promise is resolved
42+
ctrl.$pending[key] = true;
3843
expression.then(function(){
3944
ctrl.$setValidity(key, true);
4045
}, function(){

0 commit comments

Comments
 (0)