Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 36902e6

Browse files
author
Gonzalo Ruiz de Villa
committed
perf(input): should not run validators in case view value is not re-rendered
1 parent 3b662fe commit 36902e6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/ng/directive/input.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2133,10 +2133,10 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
21332133
viewValue = formatters[idx](viewValue);
21342134
}
21352135

2136-
ctrl.$$runValidators(modelValue, viewValue);
21372136

21382137
if (ctrl.$viewValue !== viewValue) {
21392138
ctrl.$viewValue = ctrl.$$lastCommittedViewValue = viewValue;
2139+
ctrl.$$runValidators(modelValue, viewValue);
21402140
ctrl.$render();
21412141
}
21422142
}

test/ng/directive/inputSpec.js

+10
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,16 @@ describe('NgModelController', function() {
667667
expect(isObject(ctrl.$pending)).toBe(false);
668668
}));
669669

670+
it('should not run validators in case view value is not re-rendered', function() {
671+
ctrl.$formatters.push(function(value) {
672+
return 'nochange';
673+
});
674+
ctrl.$validators.spyValidator = jasmine.createSpy('spyValidator');
675+
scope.$apply('value = "first"');
676+
scope.$apply('value = "second"');
677+
expect(ctrl.$validators.spyValidator).toHaveBeenCalledOnce();
678+
});
679+
670680
it('should re-evaluate the form validity state once the asynchronous promise has been delivered',
671681
inject(function($compile, $rootScope, $q) {
672682

0 commit comments

Comments
 (0)