From e6c31e411dc608f8f76826203c43252cdd2f71fd Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Tue, 12 Apr 2022 14:23:42 +0000 Subject: [PATCH] Bug 30514: Error in date format check following datepicker removal This patch corrects the is_valid_date function in the OPAC and staff interface so that it work correctly with Flatpickr. To test, apply the patch and clear your browser cache if necessary. - In the staff client, locate a bibliographic record and edit its items. - Test that the "Date acquired" date picker works correctly and that there are no errors in the browser console. - Test other date input fields to check that they still work, e.g. specify due date during checkout; Catalog statistics wizard; Patron entry/modification, etc. - Perform similar tests in the OPAC: Hold suspension; Update your personal details. Signed-off-by: David Cook Signed-off-by: Katrin Fischer --- koha-tmpl/intranet-tmpl/prog/js/calendar.js | 12 +++---- .../bootstrap/en/includes/calendar.inc | 31 ++++++++----------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/calendar.js b/koha-tmpl/intranet-tmpl/prog/js/calendar.js index 7a4a5083e8..81561cc42d 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/calendar.js +++ b/koha-tmpl/intranet-tmpl/prog/js/calendar.js @@ -1,4 +1,4 @@ -/* global debug sentmsg __ dateformat_pref dateformat_string bidi calendarFirstDayOfWeek */ +/* global debug sentmsg __ dateformat_pref flatpickr_dateformat_string bidi calendarFirstDayOfWeek */ /* exported DateTime_from_syspref flatpickr_weekdays flatpickr_months */ var MSG_PLEASE_ENTER_A_VALID_DATE = ( __("Please enter a valid date (should match %s).") ); if (debug > 1) { @@ -8,19 +8,19 @@ if (debug > 1) { function is_valid_date(date) { // An empty string is considered as a valid date for convenient reasons. if (date === '') return 1; - var dateformat = dateformat_string; + var dateformat = flatpickr_dateformat_string; if (dateformat == 'us') { if (date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1) return 0; - dateformat = 'mm/dd/yy'; + dateformat = 'm/d/Y'; } else if (dateformat == 'metric') { if (date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1) return 0; - dateformat = 'dd/mm/yy'; + dateformat = 'd/m/Y'; } else if (dateformat == 'iso') { if (date.search(/^\d{4}-\d{2}-\d{2}($|\s)/) == -1) return 0; - dateformat = 'yy-mm-dd'; + dateformat = 'Y-m-d'; } else if (dateformat == 'dmydot') { if (date.search(/^\d{2}\.\d{2}\.\d{4}($|\s)/) == -1) return 0; - dateformat = 'dd.mm.yy'; + dateformat = 'd.m.Y'; } try { flatpickr.parseDate(date, dateformat); diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc index 3a2fb12936..2cb09f2a1b 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc @@ -18,23 +18,18 @@ var calendarFirstDayOfWeek = '[% Koha.Preference('CalendarFirstDayOfWeek') | html %]'; var flatpickr_timeformat_string = [% IF Koha.Preference('TimeFormat') == '12hr' %]"G:i K"[% ELSE %]"H:i"[% END %]; var flatpickr_timeformat = [% IF Koha.Preference('TimeFormat') == '12hr' %]false[% ELSE %]true[% END %]; - var dateformat_string = ""; var flatpickr_dateformat_string = ""; switch ( dateformat_pref ){ case "us": - dateformat_string = "mm/dd/yy"; flatpickr_dateformat_string = "m/d/Y"; break; case "metric": - dateformat_string = "dd/mm/yy"; flatpickr_dateformat_string = "d/m/Y"; break; case "dmydot": - dateformat_string = "dd.mm.yy"; flatpickr_dateformat_string = "d.m.Y"; break; default: - dateformat_string = "yy-mm-dd"; flatpickr_dateformat_string = "Y-m-d"; } @@ -94,19 +89,19 @@ function is_valid_date(date) { // An empty string is considered as a valid date for convenient reasons. if (date === '') return 1; - var dateformat = dateformat_string; - if (dateformat == 'us') { - if (date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1) return 0; - dateformat = 'mm/dd/yy'; - } else if (dateformat == 'metric') { - if (date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1) return 0; - dateformat = 'dd/mm/yy'; - } else if (dateformat == 'iso') { - if (date.search(/^\d{4}-\d{2}-\d{2}($|\s)/) == -1) return 0; - dateformat = 'yy-mm-dd'; - } else if (dateformat == 'dmydot') { - if (date.search(/^\d{2}\.\d{2}\.\d{4}($|\s)/) == -1) return 0; - dateformat = 'dd.mm.yy'; + var dateformat = flatpickr_dateformat_string; + switch ( dateformat_pref ){ + case "us": + flatpickr_dateformat_string = "m/d/Y"; + break; + case "metric": + flatpickr_dateformat_string = "d/m/Y"; + break; + case "dmydot": + flatpickr_dateformat_string = "d.m.Y"; + break; + default: + flatpickr_dateformat_string = "Y-m-d"; } try { flatpickr.parseDate(date, dateformat); -- 2.30.2