Skip to content

Commit 402752c

Browse files
author
Murillo Ivamoto
committed
Executes $apply() only if doesn't have another in execution (blur)
Some components, like datepickers or combo boxes or autocompletes, has $apply() in her codes to "apply" something. Like this, sometimes "angular-validation" needs apply something too. When "angular-validation" applies something to some component and that component executes $apply() before the validation, an error is displayed in console: "$apply already in progress". To correct this, just verify if $apply() is in progress. If it isn't in progress execute him. If it is in progress, doesn't execute him.
1 parent 6163422 commit 402752c

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

dist/angular-validation.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,9 +796,14 @@ angular.module('validation.directive', ['validation.provider']);
796796
if (validMethod === 'blur') {
797797
element.bind('blur', function() {
798798
var value = scope.$eval(ngModel);
799-
scope.$apply(function() {
799+
800+
if (scope.$root.$$phase !== '$apply') {
801+
scope.$apply(function() {
802+
checkValidation(scope, element, attrs, ctrl, validation, value);
803+
});
804+
} else {
800805
checkValidation(scope, element, attrs, ctrl, validation, value);
801-
});
806+
}
802807
});
803808

804809
return;

dist/angular-validation.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/validator.directive.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,14 @@
418418
if (validMethod === 'blur') {
419419
element.bind('blur', function() {
420420
var value = scope.$eval(ngModel);
421-
scope.$apply(function() {
421+
422+
if (scope.$root.$$phase !== '$apply') {
423+
scope.$apply(function() {
424+
checkValidation(scope, element, attrs, ctrl, validation, value);
425+
});
426+
} else {
422427
checkValidation(scope, element, attrs, ctrl, validation, value);
423-
});
428+
}
424429
});
425430

426431
return;

0 commit comments

Comments
 (0)