@@ -244,6 +244,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
244
244
ngModelGet = parsedNgModel ,
245
245
ngModelSet = parsedNgModelAssign ,
246
246
pendingDebounce = null ,
247
+ parserValid ,
247
248
ctrl = this ;
248
249
249
250
this . $$setOptions = function ( options ) {
@@ -516,16 +517,12 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
516
517
// the model although neither viewValue nor the model on the scope changed
517
518
var modelValue = ctrl . $$rawModelValue ;
518
519
519
- // Check if the there's a parse error, so we don't unset it accidentially
520
- var parserName = ctrl . $$parserName || 'parse' ;
521
- var parserValid = ctrl . $error [ parserName ] ? false : undefined ;
522
-
523
520
var prevValid = ctrl . $valid ;
524
521
var prevModelValue = ctrl . $modelValue ;
525
522
526
523
var allowInvalid = ctrl . $options && ctrl . $options . allowInvalid ;
527
524
528
- ctrl . $$runValidators ( parserValid , modelValue , viewValue , function ( allValid ) {
525
+ ctrl . $$runValidators ( modelValue , viewValue , function ( allValid ) {
529
526
// If there was no change in validity, don't update the model
530
527
// This prevents changing an invalid modelValue to undefined
531
528
if ( ! allowInvalid && prevValid !== allValid ) {
@@ -543,12 +540,12 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
543
540
544
541
} ;
545
542
546
- this . $$runValidators = function ( parseValid , modelValue , viewValue , doneCallback ) {
543
+ this . $$runValidators = function ( modelValue , viewValue , doneCallback ) {
547
544
currentValidationRunId ++ ;
548
545
var localValidationRunId = currentValidationRunId ;
549
546
550
547
// check parser error
551
- if ( ! processParseErrors ( parseValid ) ) {
548
+ if ( ! processParseErrors ( ) ) {
552
549
validationDone ( false ) ;
553
550
return ;
554
551
}
@@ -558,21 +555,22 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
558
555
}
559
556
processAsyncValidators ( ) ;
560
557
561
- function processParseErrors ( parseValid ) {
558
+ function processParseErrors ( ) {
562
559
var errorKey = ctrl . $$parserName || 'parse' ;
563
- if ( parseValid === undefined ) {
560
+ if ( parserValid === undefined ) {
564
561
setValidity ( errorKey , null ) ;
565
562
} else {
566
- setValidity ( errorKey , parseValid ) ;
567
- if ( ! parseValid ) {
563
+ if ( ! parserValid ) {
568
564
forEach ( ctrl . $validators , function ( v , name ) {
569
565
setValidity ( name , null ) ;
570
566
} ) ;
571
567
forEach ( ctrl . $asyncValidators , function ( v , name ) {
572
568
setValidity ( name , null ) ;
573
569
} ) ;
574
- return false ;
575
570
}
571
+ // Set the parse error last, to prevent unsetting it, should a $validators key == parserName
572
+ setValidity ( errorKey , parserValid ) ;
573
+ return parserValid ;
576
574
}
577
575
return true ;
578
576
}
@@ -667,7 +665,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
667
665
this . $$parseAndValidate = function ( ) {
668
666
var viewValue = ctrl . $$lastCommittedViewValue ;
669
667
var modelValue = viewValue ;
670
- var parserValid = isUndefined ( modelValue ) ? undefined : true ;
668
+ parserValid = isUndefined ( modelValue ) ? undefined : true ;
671
669
672
670
if ( parserValid ) {
673
671
for ( var i = 0 ; i < ctrl . $parsers . length ; i ++ ) {
@@ -693,7 +691,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
693
691
694
692
// Pass the $$lastCommittedViewValue here, because the cached viewValue might be out of date.
695
693
// This can happen if e.g. $setViewValue is called from inside a parser
696
- ctrl . $$runValidators ( parserValid , modelValue , ctrl . $$lastCommittedViewValue , function ( allValid ) {
694
+ ctrl . $$runValidators ( modelValue , ctrl . $$lastCommittedViewValue , function ( allValid ) {
697
695
if ( ! allowInvalid ) {
698
696
// Note: Don't check ctrl.$valid here, as we could have
699
697
// external validators (e.g. calculated on the server),
@@ -814,6 +812,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
814
812
// TODO(perf): why not move this to the action fn?
815
813
if ( modelValue !== ctrl . $modelValue ) {
816
814
ctrl . $modelValue = ctrl . $$rawModelValue = modelValue ;
815
+ parserValid = undefined ;
817
816
818
817
var formatters = ctrl . $formatters ,
819
818
idx = formatters . length ;
@@ -826,7 +825,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
826
825
ctrl . $viewValue = ctrl . $$lastCommittedViewValue = viewValue ;
827
826
ctrl . $render ( ) ;
828
827
829
- ctrl . $$runValidators ( undefined , modelValue , viewValue , noop ) ;
828
+ ctrl . $$runValidators ( modelValue , viewValue , noop ) ;
830
829
}
831
830
}
832
831
0 commit comments