mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-05-28 07:57:11 +08:00
fix(ngModel): render immediately also with async validators
This commit is contained in:
@@ -2152,12 +2152,11 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
|
||||
while(idx--) {
|
||||
viewValue = formatters[idx](viewValue);
|
||||
}
|
||||
var lastViewValue = ctrl.$viewValue;
|
||||
if (lastViewValue !== viewValue) {
|
||||
ctrl.$$runValidators(undefined, modelValue, viewValue, function() {
|
||||
ctrl.$viewValue = ctrl.$$lastCommittedViewValue = viewValue;
|
||||
ctrl.$render();
|
||||
});
|
||||
if (ctrl.$viewValue !== viewValue) {
|
||||
ctrl.$viewValue = ctrl.$$lastCommittedViewValue = viewValue;
|
||||
ctrl.$render();
|
||||
|
||||
ctrl.$$runValidators(undefined, modelValue, viewValue, noop);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -407,6 +407,31 @@ describe('NgModelController', function() {
|
||||
scope.$apply('value = 5');
|
||||
expect(ctrl.$render).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('should render immediately even if there are async validators', inject(function($q) {
|
||||
spyOn(ctrl, '$render');
|
||||
ctrl.$asyncValidators.someValidator = function() {
|
||||
return $q.defer().promise;
|
||||
};
|
||||
|
||||
scope.$apply('value = 5');
|
||||
expect(ctrl.$viewValue).toBe(5);
|
||||
expect(ctrl.$render).toHaveBeenCalledOnce();
|
||||
}));
|
||||
|
||||
it('should not rerender nor validate in case view value is not changed', function() {
|
||||
ctrl.$formatters.push(function(value) {
|
||||
return 'nochange';
|
||||
});
|
||||
|
||||
spyOn(ctrl, '$render');
|
||||
ctrl.$validators.spyValidator = jasmine.createSpy('spyValidator');
|
||||
scope.$apply('value = "first"');
|
||||
scope.$apply('value = "second"');
|
||||
expect(ctrl.$validators.spyValidator).toHaveBeenCalledOnce();
|
||||
expect(ctrl.$render).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('validations pipeline', function() {
|
||||
|
||||
Reference in New Issue
Block a user