@@ -17,12 +17,14 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
17
17
yearRange : 20 ,
18
18
minDate : null ,
19
19
maxDate : null ,
20
- shortcutPropagation : false
20
+ shortcutPropagation : false ,
21
+ ngModelOptions : { }
21
22
} )
22
23
23
24
. controller ( 'UibDatepickerController' , [ '$scope' , '$attrs' , '$parse' , '$interpolate' , '$log' , 'dateFilter' , 'uibDatepickerConfig' , '$datepickerSuppressError' , function ( $scope , $attrs , $parse , $interpolate , $log , dateFilter , datepickerConfig , $datepickerSuppressError ) {
24
25
var self = this ,
25
- ngModelCtrl = { $setViewValue : angular . noop } ; // nullModelCtrl;
26
+ ngModelCtrl = { $setViewValue : angular . noop } , // nullModelCtrl;
27
+ ngModelOptions = { } ;
26
28
27
29
// Modes chain
28
30
this . modes = [ 'day' , 'month' , 'year' ] ;
@@ -94,9 +96,9 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
94
96
return false ;
95
97
} ;
96
98
97
- this . init = function ( ngModelCtrl_ ) {
99
+ this . init = function ( ngModelCtrl_ , _ngModelOptions_ ) {
98
100
ngModelCtrl = ngModelCtrl_ ;
99
-
101
+ ngModelOptions = _ngModelOptions_ && _ngModelOptions_ . $options || { } ;
100
102
ngModelCtrl . $render = function ( ) {
101
103
self . render ( ) ;
102
104
} ;
@@ -461,13 +463,15 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
461
463
customClass : '&' ,
462
464
shortcutPropagation : '&?'
463
465
} ,
464
- require : [ 'uibDatepicker' , '^ngModel' ] ,
466
+ require : [ 'uibDatepicker' , '^ngModel' , '^?ngModelOptions' ] ,
465
467
controller : 'UibDatepickerController' ,
466
468
controllerAs : 'datepicker' ,
467
469
link : function ( scope , element , attrs , ctrls ) {
468
- var datepickerCtrl = ctrls [ 0 ] , ngModelCtrl = ctrls [ 1 ] ;
470
+ var datepickerCtrl = ctrls [ 0 ] ,
471
+ ngModelCtrl = ctrls [ 1 ] ,
472
+ ngModelOptions = ctrls [ 2 ] ;
469
473
470
- datepickerCtrl . init ( ngModelCtrl ) ;
474
+ datepickerCtrl . init ( ngModelCtrl , ngModelOptions ) ;
471
475
}
472
476
} ;
473
477
} )
@@ -543,19 +547,21 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
543
547
altInputFormats : [ ]
544
548
} )
545
549
546
- . controller ( 'UibDatepickerPopupController' , [ '$scope' , '$element' , '$attrs' , '$compile' , '$parse' , '$document' , '$rootScope' , '$uibPosition' , 'dateFilter' , 'uibDateParser' , 'uibDatepickerPopupConfig' , '$timeout' ,
547
- function ( scope , element , attrs , $compile , $parse , $document , $rootScope , $position , dateFilter , dateParser , datepickerPopupConfig , $timeout ) {
550
+ . controller ( 'UibDatepickerPopupController' , [ '$scope' , '$element' , '$attrs' , '$compile' , '$parse' , '$document' , '$rootScope' , '$uibPosition' , 'dateFilter' , 'uibDateParser' , 'uibDatepickerPopupConfig' , '$timeout' , '$log' ,
551
+ function ( scope , element , attrs , $compile , $parse , $document , $rootScope , $position , dateFilter , dateParser , datepickerPopupConfig , $timeout , $log ) {
548
552
var self = this ;
549
553
var cache = { } ,
550
554
isHtml5DateInput = false ;
551
555
var dateFormat , closeOnDateSelection , appendToBody , onOpenFocus ,
552
556
datepickerPopupTemplateUrl , datepickerTemplateUrl , popupEl , datepickerEl ,
553
- ngModel , $popup , altInputFormats ;
557
+ ngModel , ngModelOptions , $popup , altInputFormats ;
554
558
555
559
scope . watchData = { } ;
556
560
557
- this . init = function ( _ngModel_ ) {
561
+ this . init = function ( _ngModel_ , _ngModelOptions_ ) {
558
562
ngModel = _ngModel_ ;
563
+
564
+ ngModelOptions = _ngModelOptions_ && _ngModelOptions_ . $options || { } ;
559
565
closeOnDateSelection = angular . isDefined ( attrs . closeOnDateSelection ) ? scope . $parent . $eval ( attrs . closeOnDateSelection ) : datepickerPopupConfig . closeOnDateSelection ;
560
566
appendToBody = angular . isDefined ( attrs . datepickerAppendToBody ) ? scope . $parent . $eval ( attrs . datepickerAppendToBody ) : datepickerPopupConfig . appendToBody ;
561
567
onOpenFocus = angular . isDefined ( attrs . onOpenFocus ) ? scope . $parent . $eval ( attrs . onOpenFocus ) : datepickerPopupConfig . onOpenFocus ;
@@ -605,6 +611,9 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
605
611
datepickerEl = angular . element ( popupEl . children ( ) [ 0 ] ) ;
606
612
datepickerEl . attr ( 'template-url' , datepickerTemplateUrl ) ;
607
613
614
+ scope . ngModelOptions = { $options : angular . extend ( { allowInvalid : false } , ngModelOptions ) } ;
615
+ datepickerEl . attr ( { 'ng-model-options' : 'ngModelOptions' } ) ;
616
+
608
617
if ( isHtml5DateInput ) {
609
618
if ( attrs . type === 'month' ) {
610
619
datepickerEl . attr ( 'datepicker-mode' , '"month"' ) ;
@@ -826,14 +835,12 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
826
835
827
836
if ( angular . isString ( viewValue ) ) {
828
837
var date = parseDateString ( viewValue ) ;
829
- if ( isNaN ( date ) ) {
830
- return undefined ;
838
+ if ( ! isNaN ( date ) ) {
839
+ return date ;
831
840
}
832
-
833
- return date ;
834
841
}
835
842
836
- return undefined ;
843
+ return ngModelOptions && ngModelOptions . allowInvalid ? viewValue : undefined ;
837
844
}
838
845
839
846
function validator ( modelValue , viewValue ) {
@@ -899,7 +906,7 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
899
906
900
907
. directive ( 'uibDatepickerPopup' , function ( ) {
901
908
return {
902
- require : [ 'ngModel' , 'uibDatepickerPopup' ] ,
909
+ require : [ 'ngModel' , 'uibDatepickerPopup' , '^?ngModelOptions' ] ,
903
910
controller : 'UibDatepickerPopupController' ,
904
911
scope : {
905
912
isOpen : '=?' ,
@@ -911,9 +918,10 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
911
918
} ,
912
919
link : function ( scope , element , attrs , ctrls ) {
913
920
var ngModel = ctrls [ 0 ] ,
914
- ctrl = ctrls [ 1 ] ;
921
+ ctrl = ctrls [ 1 ] ,
922
+ ngModelOptions = ctrls [ 2 ] ;
915
923
916
- ctrl . init ( ngModel ) ;
924
+ ctrl . init ( ngModel , ngModelOptions ) ;
917
925
}
918
926
} ;
919
927
} )
0 commit comments