From 86ea782eb54f84b7afab2762e744089280851f11 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 --- .../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 231d97d48ae..bd8c9e7b863 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.25.1