-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix(input): $asyncValidators should allow $parsers #8892
Conversation
This doesn't seem quite right to me, because we've already parsed the value before async validators ever started running. there's probably a bug but I don't think this is the right fix. @matsko? |
b24319c
to
a1d0da2
Compare
That's the problem. The value is parsed and stored in currentValue. After resolving the async validator, the stored value is compared against the viewValue. No unit test nor e2e tests fails, if I remove this comparison, so, a priori, this would be much faster/better. function resolve(bool) {
return function() {
if (ctrl.$pending && ctrl.$pending[validationErrorKey]) {
pendingCount--;
delete ctrl.$pending[validationErrorKey];
ctrl.$setValidity(validationErrorKey, bool);
if (pendingCount === 0) {
ctrl.$$clearPending();
ctrl.$$updateValidModelValue(currentValue);
ctrl.$$writeModelToScope();
}
}
};
} I guess that the comparison is done because the viewValue may change while the asyncValidation is being done. In this case, it maybe be worth storing both the old viewValue and modelValue, and re-executing the parsers only if the viewValue has changed. |
a1d0da2
to
2fed968
Compare
I've updated the code. Now, it's much cleaner and I think it reflects what it was meant to do. I think the problem was the |
Thanks =) |
2fed968
to
92d0317
Compare
This looks really good. I will review it later today and we can get it in tomorrow. |
I already submitted a PR for this: #8861 |
@shahata Sorry, I didn't saw your PR. I've reviewed it and I've seen a problem with it. Your are calling in line 1740 |
92d0317
to
1ca0726
Compare
Yeah, that required a minor fix in my PR. Good catch. Anyway, I like mine a bit more since it makes |
After resolving an async validator, it should compare current viewValue against the value it had when the validator was started before reducing pendingCount. Before this commit the comparison was made between the modelValue when the validation started and the current viewValue.
1ca0726
to
36902e6
Compare
I have updated my PR with the perf boost. However, I like more @shahata PR. Not only the signatures have less arguments, but in my PR, the arguments I think that you should put the performance change and test in a separate commit. |
After resolving the async validators, it should execute all parsers
on the viewValue before comparing it to the currentValue.
Currently, input[type=number] is not recognizing the end of the async validation because
the comparison
currentValue === value
is comparing a number incurrentValue
against a string invalue
https://github.com/angular/angular.js/blob/master/src/ng/directive/input.js#L1734