@@ -510,11 +510,6 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
510
510
511
511
} else {
512
512
513
- ngModelCtrl . $isEmpty = function ( value ) {
514
- return ! value || value . length === 0 ;
515
- } ;
516
-
517
-
518
513
selectCtrl . writeValue = function writeNgOptionsMultiple ( value ) {
519
514
options . items . forEach ( function ( option ) {
520
515
option . element . selected = false ;
@@ -558,6 +553,42 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
558
553
}
559
554
}
560
555
556
+ function isViewOptionValid ( viewValue ) {
557
+
558
+ var isValidOption = false ;
559
+ var viewOptions = [ ] ;
560
+ // Get all option and add them to viewOptions array
561
+ angular . forEach ( options . items , function ( item ) {
562
+ viewOptions . push ( options . getViewValueFromOption ( item ) ) ;
563
+ } ) ;
564
+
565
+ // In case of multiple view is an array so validate all view values
566
+ // if one of them match set isValidOption to true
567
+ if ( multiple ) {
568
+ for ( var i = 0 , length = viewValue . length ; i < length ; i ++ ) {
569
+ if ( viewOptions . indexOf ( viewValue [ i ] ) > - 1 ) {
570
+ isValidOption = true ;
571
+ break ;
572
+ }
573
+ }
574
+ } else {
575
+ if ( viewOptions . indexOf ( viewValue ) > - 1 ) {
576
+ isValidOption = true ;
577
+ }
578
+ }
579
+
580
+ return isValidOption ;
581
+ }
582
+
583
+ // Copy the implementation of $isEmpty function to be used in overwritten one
584
+ var $$isEmpty = ngModelCtrl . $isEmpty ;
585
+
586
+ ngModelCtrl . $isEmpty = function ( value ) {
587
+ if ( $$isEmpty ( value ) ) {
588
+ return true ;
589
+ }
590
+ return ! isViewOptionValid ( value ) ;
591
+ } ;
561
592
562
593
if ( providedEmptyOption ) {
563
594
0 commit comments