From d57219a86c2bae0777ba34b6cea8f2f3a35e372f Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Mon, 23 Sep 2024 16:23:13 +0000 Subject: [PATCH] Bug 37398: Add set to today function to calendar.inc To test: 1. Try editing some items with a empty value in the flatpickr. 2. Make sure the empty date fields get a date set to today when you click on the empty field. 3. Try a datetime field, making sure the datetime is correctly set. --- koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc | 9 +++++++++ .../intranet-tmpl/prog/en/includes/html_helpers.inc | 4 ++-- 2 files changed, 11 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 9f1cdb6ceb2..384ade62cc8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc @@ -122,6 +122,15 @@ } } }, + onOpen: function( selectedDates, dateText, instance) { + var thisInput = instance.input; + let set_to_today = $(thisInput).data('flatpickr-set-to-today'); + if ( set_to_today ) { + if ( thisInput.value === '' ) { + instance.setDate( new Date() ); + } + } + }, onClose: function( selectedDates, dateText, instance) { validate_date( dateText, instance ); var thisInput = instance.input; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc index 48c1c682f33..ead708ade3a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc @@ -167,9 +167,9 @@ [% END %] [% ELSIF ( mv.type == 'date_field' ) %] - + [% ELSIF ( mv.type == 'datetime_field' ) %] - + [% END %] [% IF subfield.kohafield == 'items.more_subfields_xml' %] -- 2.39.2