From 6cc3e618d84c85ed353392006fc06ed094b46f27 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 17 Nov 2021 11:22:57 +0100 Subject: [PATCH] Bug 29500: Flatpickr - accept original date in the past and not others Bug 29241 was supposed to fix this but it didn't properly. We are accepting other dates in the past when we should only accept the original one (the one from the DB) AND dates in future. Test plan: Retry test plan for 29241 and confirm that you cannot set manually another date in the past. Signed-off-by: Owen Leonard Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- .../intranet-tmpl/prog/en/includes/calendar.inc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc index 8489c25aca..eebb7ff699 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc @@ -90,8 +90,20 @@ let options = {}; if( $(this).data("flatpickr-futuredate") === true ) { - options['minDate'] = new Date().fp_incr(1); - options['allowInvalidPreload'] = true; + let original_date = $(this).val(); + if ( original_date ) { + original_date = Date_from_syspref( original_date ).getTime(); + let tomorrow = new Date().fp_incr(1).getTime(); + + options['enable'] = [function(date){ + date = date.getTime(); + if ( date == original_date ) return true; + if ( date >= tomorrow) return true; + }]; + } + else { + options['minDate'] = new Date().fp_incr(1); + } } if( $(this).data("flatpickr-pastinclusive") === true ) { options['maxDate'] = "today"; -- 2.39.5