From b046b1da98f9ecd3dd8c0191a1686174031a894a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 23 Nov 2021 14:17:09 +0100 Subject: [PATCH] Bug 29552: Flatpickr - Disable shortcut buttons if inactive If one of the buttons is not relevant we should disable it and mark is as such on the interface. Signed-off-by: Owen Leonard Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer Signed-off-by: Fridolin Somers --- koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc index 8360890241..7b2ba63aac 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc @@ -127,6 +127,7 @@ $(".flatpickr").each(function(){ let options = {}; let refresh_max_date = 0; + let disable_buttons = []; if( $(this).data("flatpickr-futuredate") === true ) { let original_date = $(this).val(); @@ -143,13 +144,17 @@ else { options['minDate'] = new Date().fp_incr(1); } + disable_buttons.push(0); /* Yesterday */ } if( $(this).data("flatpickr-pastinclusive") === true ) { options['maxDate'] = new Date(); /* Not today or hh:mm will be 00:00 */ refresh_max_date = 1; + disable_buttons.push(2); /* Tomorrow */ } if( $(this).data("flatpickr-pastdate") === true ) { options['maxDate'] = new Date().fp_incr(-1); + disable_buttons.push(1); /* Today */ + disable_buttons.push(2); /* Tomorrow */ } if ( $(this).data('flatpickr-enable-time') === true ) { options['enableTime'] = true; @@ -157,6 +162,11 @@ } let fp = $(this).flatpickr(options); + + $(disable_buttons).each(function(index, value){ + $(fp.calendarContainer).find(".shortcut-buttons-flatpickr-button[data-index='"+value+"']").prop("disabled", "disabled").css("color", "#999"); + }); + if ( refresh_max_date ) { /* Refresh the maxDate every 30 secondes to make sure the user will not be stuck with the minute passed. -- 2.39.5