@@ -457,7 +457,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
457
457
closeText : 'Done' ,
458
458
closeOnDateSelection : true ,
459
459
appendToBody : false ,
460
- showButtonBar : true
460
+ showButtonBar : true ,
461
+ openOnFocus : false
461
462
} )
462
463
463
464
. directive ( 'datepickerPopup' , [ '$compile' , '$parse' , '$document' , '$position' , 'dateFilter' , 'dateParser' , 'datepickerPopupConfig' ,
@@ -476,7 +477,8 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
476
477
link : function ( scope , element , attrs , ngModel ) {
477
478
var dateFormat ,
478
479
closeOnDateSelection = angular . isDefined ( attrs . closeOnDateSelection ) ? scope . $parent . $eval ( attrs . closeOnDateSelection ) : datepickerPopupConfig . closeOnDateSelection ,
479
- appendToBody = angular . isDefined ( attrs . datepickerAppendToBody ) ? scope . $parent . $eval ( attrs . datepickerAppendToBody ) : datepickerPopupConfig . appendToBody ;
480
+ appendToBody = angular . isDefined ( attrs . datepickerAppendToBody ) ? scope . $parent . $eval ( attrs . datepickerAppendToBody ) : datepickerPopupConfig . appendToBody ,
481
+ openOnFocus = angular . isDefined ( attrs . datepickerOpenOnFocus ) ? scope . $parent . $eval ( attrs . datepickerOpenOnFocus ) : datepickerPopupConfig . openOnFocus ;
480
482
481
483
scope . showButtonBar = angular . isDefined ( attrs . showButtonBar ) ? scope . $parent . $eval ( attrs . showButtonBar ) : datepickerPopupConfig . showButtonBar ;
482
484
@@ -642,9 +644,11 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
642
644
element . val ( date ) ;
643
645
ngModel . $setViewValue ( date ) ;
644
646
645
- if ( closeOnDateSelection ) {
647
+ if ( closeOnDateSelection ) {
646
648
scope . isOpen = false ;
647
- element [ 0 ] . focus ( ) ;
649
+ if ( ! openOnFocus ) {
650
+ element [ 0 ] . focus ( ) ;
651
+ }
648
652
}
649
653
} ;
650
654
@@ -677,6 +681,16 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
677
681
scope . isOpen = true ;
678
682
}
679
683
} ;
684
+
685
+ var focus = function ( ) {
686
+ scope . $apply ( function ( ) {
687
+ scope . isOpen = true ;
688
+ } ) ;
689
+ } ;
690
+
691
+ if ( openOnFocus ) {
692
+ element . bind ( 'focus' , focus ) ;
693
+ }
680
694
681
695
scope . $watch ( 'isOpen' , function ( value ) {
682
696
if ( value ) {
@@ -721,6 +735,7 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
721
735
scope . $on ( '$destroy' , function ( ) {
722
736
$popup . remove ( ) ;
723
737
element . unbind ( 'keydown' , keydown ) ;
738
+ element . unbind ( 'focus' , focus ) ;
724
739
$document . unbind ( 'click' , documentClickBind ) ;
725
740
} ) ;
726
741
}
0 commit comments