Search code examples
bootstrap-timepicker

bootstrap-timepicker - get only years and month - dont show day selector


Im using bootstrap-timepicker: https://eonasdan.github.io/bootstrap-datetimepicker/#min-view-mode and using the "Min View Mode" because i only want to get a year and month. no "day". In their example its working fine. But when i use it, first you select a year, then a month then it works. But when you change this val it shows a day picker.

It must show the year or the month but not the day.

codepen here: http://codepen.io/r2get/pen/bwaZog

<div class="col-xs-12 product-prijs-cont">
    <div class="row">
        <div class="col-md-6">
            <h1 class="custom-h1" style="border:0;"><i class="fa fa-sliders supp-color-price-page"></i>&nbsp;Filter jaar</h1>
        </div>
        <div class="col-md-6 padding-bottom-year-filter">
            <div class="input-group date" id="datetimepicker" style="margin-top:-3px;">
                <input type="text" id="yearSelector" class="form-control input-group-addon" />
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
            </div>
        </div>
    </div>
</div>

at first input it works select year first then month and it shows a year and month. But on second try (change) it must show a year or month, but it shows day


Solution

  • According to bootstrap-datetimepicker.js source code current view mode is getting reseted (no idea why, it probaly would be better contact contributors of this library) once the popup is closed:

    currentViewMode = 0; 
    

    That's the reason why the next time the default view (days) is displayed.

    Workaround

    One option would be to force display years view once the popup is displayed:

    $("#datetimepicker").on("dp.show", function (e) {
           $('.datepicker-days').hide();
           $('.datepicker-years').show();
      });
    

    Demo

    Updated codepen