From 2f01f12d94d74f95f772b4116efabeaef5a1b348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Tue, 27 May 2014 13:23:44 -0400 Subject: [PATCH] Undefined args --- src/ng/directive/input.js | 21 +++++++++++++-------- test/ng/directive/inputSpec.js | 8 ++++---- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index 5380498b7e5d..e3701ee484b7 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -1763,8 +1763,11 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ * Runs each of the registered validations set on the $validators object. */ this.$validate = function(modelValue, viewValue) { - modelValue = modelValue || ctrl.$modelValue; - viewValue = viewValue || ctrl.$viewValue; + if(arguments.length === 0) { + modelValue = ctrl.$modelValue; + viewValue = ctrl.$viewValue; + } + forEach(ctrl.$validators, function(fn, name) { ctrl.$setValidity(name, fn(modelValue, viewValue)); }); @@ -1803,11 +1806,12 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ modelValue = fn(modelValue); }); - if (ctrl.$modelValue !== modelValue && (!ctrl.$rawModelValue || ctrl.$rawModelValue != modelValue)) { + if (ctrl.$modelValue !== modelValue && + (isUndefined(ctrl.$$invalidModelValue) || ctrl.$$invalidModelValue != modelValue)) { ctrl.$validate(modelValue, viewValue); - ctrl.$modelValue = ctrl.$valid ? modelValue : undefined; - ctrl.$rawModelValue = ctrl.$valid ? undefined : modelValue; + ctrl.$modelValue = ctrl.$valid ? modelValue : undefined; + ctrl.$$invalidModelValue = ctrl.$valid ? undefined : modelValue; ngModelSet($scope, ctrl.$modelValue); forEach(ctrl.$viewChangeListeners, function(listener) { @@ -1886,7 +1890,8 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ var modelValue = ngModelGet($scope); // if scope model value and ngModel value are out of sync - if (ctrl.$modelValue !== modelValue && (!ctrl.$rawModelValue || ctrl.$rawModelValue != modelValue)) { + if (ctrl.$modelValue !== modelValue && + (isUndefined(ctrl.$$invalidModelValue) || ctrl.$$invalidModelValue != modelValue)) { var formatters = ctrl.$formatters, idx = formatters.length; @@ -1897,8 +1902,8 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ } ctrl.$validate(modelValue, viewValue); - ctrl.$modelValue = ctrl.$valid ? modelValue : undefined; - ctrl.$rawModelValue = ctrl.$valid ? undefined : modelValue; + ctrl.$modelValue = ctrl.$valid ? modelValue : undefined; + ctrl.$$invalidModelValue = ctrl.$valid ? undefined : modelValue; if (ctrl.$viewValue !== viewValue) { ctrl.$viewValue = ctrl.$$lastCommittedViewValue = viewValue; diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index 206c6218145a..545d70a2c7d8 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -360,16 +360,16 @@ describe('NgModelController', function() { } val(''); - expect(count).toBe(2); + expect(count).toBe(1); val(1); - expect(count).toBe(3); + expect(count).toBe(2); val(1); - expect(count).toBe(3); + expect(count).toBe(2); val(''); - expect(count).toBe(4); + expect(count).toBe(3); }); it('should only validate to true if all validations are true', function() {