I’ve updated bootstrap from version 3 to 4 and noticed the calendar is overlapping when creating it with js instead of cshtml. There’s no need to go back more than a few days so I would like to disable the month button that changes the view mode to months or years. Is there a specific CSS property that I need or would I need to edit a code in the library?
function AddDateTimeControl(parent, control, rowIndex, controlIndex) {
var dateTimeID = "datetimepicker" + controlIndex;
var tooltipDiv = CreateTooltipDiv();
var tooltipSpan = CreateTooltipSpan(control.ToolTip);
var label = CreateControlLabel(control);
//var icon = CreateIcon('fa-calendar');
var icon = CreateIcon("calendar-alt-regular");
tooltipDiv.appendChild(label);
tooltipDiv.appendChild(icon);
tooltipDiv.appendChild(tooltipSpan);
var dateDiv = document.createElement("div");
dateDiv.classList.add('input-group');
dateDiv.classList.add('date');
dateDiv.classList.add('date-time-control');
dateDiv.style.color = "black";
dateDiv.id = dateTimeID;
var dateTextBox = document.createElement("input");
dateTextBox.type = "text";
dateTextBox.classList.add("form-control");
dateTextBox.value = control.RawValues[0];
MarkElementForSerialization(dateTextBox, rowIndex, control.ID, 0);
var calControlSpan = document.createElement("span");
calControlSpan.classList.add('input-group-append'); //input-group-addon?
//span -> fa-calendar?
dateDiv.appendChild(dateTextBox);
dateDiv.appendChild(calControlSpan); //input-group-addon
parent.appendChild(tooltipDiv);
parent.appendChild(dateDiv);
$(dateDiv).datetimepicker();
$(dateDiv).data("DateTimePicker").sideBySide(true);
$(dateDiv).data("DateTimePicker").date(new Date(Date.parse(control.RawValues[0])));
$(dateDiv).data("DateTimePicker").format("MM/DD/YYYY HH:mm");
$(dateDiv).data("DateTimePicker").icons({
time: "fa fa-clock-o",
date: "fa fa-calendar",
up: "fa fa-arrow-up",
down: "fa fa-arrow-down",
previous: "fa fa-chevron-left",
next: "fa fa-chevron-right",
today: "fa fa-clock-o",
clear: "fa fa-trash-o"
});
$(dateTextBox).on('click', function() {
$(dateDiv).data("DateTimePicker").toggle();
});
}
2
Answers
I ended up disabling it by disabling the pointer event in the month picker switch.
That will depend entirely on which datetimepicker component you are using.
This one lets you set the maximum view:
However, it was never updated to support Bootstrap 4.
That picker has since been deprecated in favour of eonasdan-bootstrap-datetimepicker, which has an option to set the minimum view, but not the maximum view. You would need to dig in to the code for that version if you wanted to add that option.
There is a newer version of the Eonasdan picker, now called tempus dominus, which is currently in alpha. That version provides options to turn the individual views on or off: