How to get current viewMode property from "Bootstrap Datepicker"

12,946

Solution 1

Check this : 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');
   }
})

Solution 2

If you're using the forked version of Bootstrap Datepicker, to close the UI widget when a date is selected, set the autoclose option to true:

$("#date").datepicker({
    autoclose: true
});
Share:
12,946
Gonzalo
Author by

Gonzalo

Updated on July 11, 2022

Comments

  • Gonzalo
    Gonzalo almost 2 years

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

    The user selects a year, then a month, and finally a day. In that moment the control must 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?