Skip to content

Commit

Permalink
Executes $apply() only if doesn't have another in execution (blur)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Murillo Ivamoto committed Feb 6, 2017
1 parent 6163422 commit 402752c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
9 changes: 7 additions & 2 deletions dist/angular-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -796,9 +796,14 @@ angular.module('validation.directive', ['validation.provider']);
if (validMethod === 'blur') {
element.bind('blur', function() {
var value = scope.$eval(ngModel);
scope.$apply(function() {

if (scope.$root.$$phase !== '$apply') {
scope.$apply(function() {
checkValidation(scope, element, attrs, ctrl, validation, value);
});
} else {
checkValidation(scope, element, attrs, ctrl, validation, value);
});
}
});

return;
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-validation.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions src/validator.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,14 @@
if (validMethod === 'blur') {
element.bind('blur', function() {
var value = scope.$eval(ngModel);
scope.$apply(function() {

if (scope.$root.$$phase !== '$apply') {
scope.$apply(function() {
checkValidation(scope, element, attrs, ctrl, validation, value);
});
} else {
checkValidation(scope, element, attrs, ctrl, validation, value);
});
}
});

return;
Expand Down

0 comments on commit 402752c

Please sign in to comment.