Skip to content

Commit

Permalink
Undefined args
Browse files Browse the repository at this point in the history
  • Loading branch information
matsko committed May 27, 2014
1 parent 5c88424 commit 2f01f12
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
21 changes: 13 additions & 8 deletions src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions test/ng/directive/inputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 2f01f12

Please sign in to comment.