diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index 0c7664e1d02e..d7676f2eb96c 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -1755,8 +1755,11 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ */ this.$commitViewValue = function() { var value = ctrl.$viewValue; - ctrl.$$lastCommittedViewValue = value; $timeout.cancel(pendingDebounce); + if (ctrl.$$lastCommittedViewValue === value) { + return; + } + ctrl.$$lastCommittedViewValue = value; // change to dirty if (ctrl.$pristine) { diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index e1d7ff2c9e4e..c026f9a455a9 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -170,7 +170,7 @@ describe('NgModelController', function() { // invalid ctrl.$parsers.push(function() {return undefined;}); - ctrl.$setViewValue('val'); + ctrl.$setViewValue('val2'); expect(spy).toHaveBeenCalledOnce(); }); @@ -643,6 +643,16 @@ describe('input', function() { expect(scope.name).toEqual('a'); }); + it('should not dirty the input if nothing was changed before updateOn trigger', function() { + compileInput( + '<input type="text" ng-model="name" name="alias" '+ + 'ng-model-options="{ updateOn: \'blur\' }"'+ + '/>'); + + browserTrigger(inputElm, 'blur'); + expect(scope.form.alias.$pristine).toBeTruthy(); + }); + it('should allow overriding the model update trigger event on text areas', function() { compileInput( '<textarea ng-model="name" name="alias" '+