From 44ddbf8ec781a08206e43b7202b7c779db310725 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 14 Oct 2021 11:36:02 +0200 Subject: [PATCH] Bug 29241: Allow display of past date for .futuredate When a past date is set for a flatpickr instance with the .futuredate class, only dates in the future are available AND the input is blanked. It does not display the date in the past. For instance if a hold is expired (expirationdate in the past), the date input will be blanked. We can use the flatpickr's allowInvalidPreload option to allow date in the past to be displayed. Test plan: Place a hold Edit its expirationdate and set a date in the past (yesterday is fine) Go to /reserve/request.pl?biblionumbers=42 => With the patch you see the date, and the widget let you chose anoter date, in the future => Without this patch the expiration date is not displayed Signed-off-by: David Nind Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- .../prog/en/includes/calendar.inc | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc index 231d97d48a..bd8c9e7b86 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc @@ -31,12 +31,6 @@ }, onReady: function( selectedDates, dateStr, instance ){ /* When flatpickr instance is created, automatically append a "clear date" link */ - if( $(instance.input).hasClass("futuredate") ){ - instance.set("minDate", new Date().fp_incr(1)); - } - if( $(instance.input).hasClass("pastdate") ){ - instance.set("maxDate", new Date().fp_incr(-1)); - } $(instance.input) /* Add a wrapper element so that we can prevent the clear button from wrapping */ .wrap("") @@ -67,7 +61,18 @@ }, }); $(document).ready(function(){ - $(".flatpickr").flatpickr(); + $(".flatpickr").each(function(){ + let options = {}; + + if( $(this).hasClass("futuredate") ) { + options['minDate'] = new Date().fp_incr(1); + options['allowInvalidPreload'] = true; + } + if( $(this).hasClass("pastdate") ) { + options['maxDate'] = new Date().fp_incr(-1); + } + $(this).flatpickr(options); + }); }); [% END %] -- 2.39.5