From 541adb4bd25c191c8ef45b07a7eb889791b8578f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 17 Nov 2021 12:19:50 +0100 Subject: [PATCH] Bug 29478: Today should select now for pastinclusive If Today is clicked when we only allow dates in the past and today/now, we should select the current date/time We need to update the maxDate to make it up-to-date, or the maxDate may be set to the minute before and clicking Today will blank the input. Signed-off-by: Owen Leonard Signed-off-by: David Nind Signed-off-by: Martin Renvoize --- .../prog/en/includes/calendar.inc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc index 83ae48013e..11c8ee4e50 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc @@ -101,18 +101,23 @@ label: __("or"), onClick: (index, fp) => { let date; + let hh = 23, mm = 59; switch (index) { case 0: date = new Date().fp_incr(-1); break; case 1: date = new Date(); + if ( $(fp.input).data("flatpickr-pastinclusive") === true ) { + hh = date.getHours(); + mm = date.getMinutes(); + } break; case 2: date = new Date().fp_incr(1); break; } - date.setHours(23, 59, 0, 0); + date.setHours(hh, mm, 0, 0); fp.setDate(date); } }) @@ -121,6 +126,7 @@ $(document).ready(function(){ $(".flatpickr").each(function(){ let options = {}; + let refresh_max_date = 0; if( $(this).data("flatpickr-futuredate") === true ) { let original_date = $(this).val(); @@ -139,7 +145,8 @@ } } if( $(this).data("flatpickr-pastinclusive") === true ) { - options['maxDate'] = "today"; + options['maxDate'] = new Date(); /* Not today or hh:mm will be 00:00 */ + refresh_max_date = 1; } if( $(this).data("flatpickr-pastdate") === true ) { options['maxDate'] = new Date().fp_incr(-1); @@ -149,7 +156,12 @@ options['dateFormat'] = flatpickr_dateformat_string + " " + flatpickr_timeformat_string; } - $(this).flatpickr(options); + let fp = $(this).flatpickr(options); + if ( refresh_max_date ) { + /* Refresh the maxDate every 30 secondes to make sure the user will not + be stuck with the minute passed */ + setInterval(() => { fp.set("maxDate", new Date()) }, 30000); + } }); }); -- 2.20.1