Fix datepicker date display when using min/max (Z#23185544)

This commit is contained in:
Richard Schreiber
2025-04-16 18:12:27 +02:00
committed by GitHub
parent 08eabfa61c
commit 929a2eb6e3
2 changed files with 18 additions and 2 deletions

View File

@@ -196,7 +196,15 @@ var form_handlers = function (el) {
}
if ($(this).is('[data-is-payment-date]'))
opts["daysOfWeekDisabled"] = JSON.parse($("body").attr("data-payment-weekdays-disabled"));
$(this).datetimepicker(opts);
$(this).datetimepicker(opts).on("dp.hide", function() {
// when min/max is used in datetimepicker, closing and re-opening the picker opens at the wrong date
// therefore keep the current viewDate and re-set it after datetimepicker is done hiding
var $dtp = $(this).data("DateTimePicker");
var currentViewDate = $dtp.viewDate();
window.setTimeout(function () {
$dtp.viewDate(currentViewDate);
}, 50);
});
if ($(this).parent().is('.splitdatetimerow')) {
$(this).on("dp.change", function (ev) {
var $timepicker = $(this).closest(".splitdatetimerow").find(".timepickerfield");

View File

@@ -82,7 +82,15 @@ var form_handlers = function (el) {
Math.abs(+new Date(opts.minDate) - new Date()) < Math.abs(+new Date(opts.maxDate) - new Date())
) ? opts.minDate : opts.maxDate;
}
$(this).datetimepicker(opts);
$(this).datetimepicker(opts).on("dp.hide", function() {
// when min/max is used in datetimepicker, closing and re-opening the picker opens at the wrong date
// therefore keep the current viewDate and re-set it after datetimepicker is done hiding
var $dtp = $(this).data("DateTimePicker");
var currentViewDate = $dtp.viewDate();
window.setTimeout(function () {
$dtp.viewDate(currentViewDate);
}, 50);
});
if ($(this).parent().is('.splitdatetimerow')) {
$(this).on("dp.change", function (ev) {
var $timepicker = $(this).closest(".splitdatetimerow").find(".timepickerfield");