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

fix(ngModel): do not dirty the input if nothing was changed #7495

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ng/directive/input.js
Original file line number Diff line number Diff line change
@@ -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) {
12 changes: 11 additions & 1 deletion test/ng/directive/inputSpec.js
Original file line number Diff line number Diff line change
@@ -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" '+