How to get current viewMode property from "Bootstrap Datepicker"

How to get current viewMode property from "Bootstrap Datepicker"? I initialize the control with viewMode= 'years' , and I want to close the datepicker on the changeDate event only when viewMode='days' .

The user selects a year, then a month, and finally a day. At this point, control should be closed.

This is the code:

 $("#date").datepicker( {viewMode: 'years', format: 'dd/mm/yyyy' }); $('#date').on('changeDate', function (ev) { //close when viewMode='0' (days) }) 

Can anyone help?

+4
source share
2 answers

Check this out: http://jsfiddle.net/nAXnM/

HTML

  <input type="text" class="span2" value="02/16/12" data-date-format="mm/dd/yy" id="dp2" > 

Js

 $("#dp2").datepicker({ viewMode: 'years', format: 'dd/mm/yyyy' }); $('#dp2').on('changeDate', function (ev) { //close when viewMode='0' (days) if(ev.viewMode === 'days'){ $('#dp2').datepicker('hide'); } }) 
+7
source

If you are using the forked version of Bootstrap Datepicker to close the user interface widget when selecting a date, set the autoclose option to true :

 $("#date").datepicker({ autoclose: true }); 
+1
source

All Articles