Sarpe Sarpe - 7 months ago 375
Javascript Question

Bootstrap Datetimepicker - Disable decades view mode

When the user clicks on the view header multiple times the expected behaviour is: days -> months -> years -> decades.
I need to disable the decades view (screenshot attached).
Doing so the user cannot go further 'year' view mode.

enter image description here

Answer

here is a workaround, thanks to RomeroMsk for this.

CSS:

.datepicker-years .picker-switch {
cursor: default !important;
background: inherit !important;
}

JS:

$('#datetimepicker1').datetimepicker({
// your datetimepicker options go here, f.i.:
        inline: true,
        sideBySide: false,
        format : "DD/MMM/YYYY",
        maxDate : moment()
}).on('dp.show dp.update', function () {
$(".datepicker-years .picker-switch").removeAttr('title')
    //.css('cursor', 'default')  <-- this is not needed if the CSS above is used
    //.css('background', 'inherit')  <-- this is not needed if the CSS above is used
    .on('click', function (e) {
        e.stopPropagation();
    });
});
Comments