From aaa3954c8f4a82620d06e20f42acb3f0af45dfce Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Tue, 7 Jul 2026 14:23:27 +0300 Subject: [PATCH] Bug 38358: Do not allow selecting past dates when editing existing holidays "To date" input When you are editing holidays "To date" inputs calendar doesn't follow the "From date" date. Instead calendar offers you today's date/month and you must click calendar forward to the right date/month. This patch adds check to determine if user is adding new holiday or editing existing one and adjusts the code to disable past dates counting from selected "From date" in both cases. To test: 1. Navigate to calendar tool (Tools->Calendar). 2. Add new holiday and select "To date" for it. => Note that you are unable to select dates past from "From date". 3. Edit existing holiday and select "To date" for it. => Note that "To date" input calendar allows selecting dates past "From date". => If you chosed holiday from incoming month, note that "To date" calendar still opens up to this month. 4. Apply this patch, restart services if needed. 5. Edit existing holiday again. => Note that now "To date" inputs calendar works the same way as it is working when your adding a new holiday. Sponsored-by: Koha-Suomi Oy Signed-off-by: Laura_Escamilla Signed-off-by: Paul Derscheid Signed-off-by: Pedro Amorim --- .../prog/en/modules/tools/holidays.tt | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt index 0e4ac4482e..680a6e72c7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt @@ -668,19 +668,32 @@ }, onChange: function (selectedDates, dateStr, instance) { var fromdate = selectedDates[0]; - var enddate = dateofrange.selectedDates[0]; dateChanged(fromdate); - dateofrange.set("defaultDate", fromdate); - dateofrange.set("minDate", fromdate); - - if (enddate != undefined) { - if (enddate < fromdate) { - dateofrange.set("defaultDate", fromdate); - dateofrange.setDate(fromdate); + /* we need to wait animations to complete in order + to determine if calendar opened is for adding a new + holiday or for editing an existing one */ + setTimeout(function () { + var calendar; + if ($("#newHoliday").is(":visible")) { + calendar = dateofrange; + } else if ($("#showHoliday").is(":visible")) { + calendar = datecancelrange; } - } + + var enddate = calendar.selectedDates[0]; + + calendar.set("defaultDate", fromdate); + calendar.set("minDate", fromdate); + + if (enddate != undefined) { + if (enddate < fromdate) { + calendar.set("defaultDate", fromdate); + calendar.setDate(fromdate); + } + } + }, 250); }, defaultDate: new Date(keydate), });