From a3870cc25b40379e0f538c3b3c08fb8fe3540a8e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 9 May 2022 10:28:51 +0200 Subject: [PATCH] Bug 30717: Format dates when editing items This is a result of bug 29369 and bug 27526. Bug 29369 removed the format of the dates, and bug 27526 assumed that it was the correct behaviour. Here we don't want to let the controller know which fields is a date, or we will have to access the subfield structure to know which subfields have the "date cataloguing plugin". This patch suggests to use the altFormat options from flatpickr that will "Show the user a readable date (as per altFormat), but return something totally different to the server." It's actually an option we want to use for all our dates, that will reduce a lot the overhead in our controllers. Test plan: Edit items (additem.pl and in batch) and confirm that the subfields using the dateaccessioned plugin are displayed according to the dateformat syspref. Make sure the date is stored correctly. Signed-off-by: David Nind Signed-off-by: Marcel de Rooy Signed-off-by: Fridolin Somers --- cataloguing/value_builder/dateaccessioned.pl | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cataloguing/value_builder/dateaccessioned.pl b/cataloguing/value_builder/dateaccessioned.pl index 6532d29b07..272b5aecfe 100755 --- a/cataloguing/value_builder/dateaccessioned.pl +++ b/cataloguing/value_builder/dateaccessioned.pl @@ -27,7 +27,14 @@ my $builder = sub { my ( $params ) = @_; my $function_name = $params->{id}; - my $date = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }); + my $date = output_pref({ dt => dt_from_string, dateonly => 1 }); + + my $dateformat_pref = C4::Context->preference('dateformat'); + my $dateformat = + $dateformat_pref eq 'us' ? 'm/d/Y' + : $dateformat_pref eq 'metric' ? 'd/m/Y' + : $dateformat_pref eq 'dmydot' ? 'd.m.Y' + : 'Y-m-d'; my $res = < @@ -35,6 +42,9 @@ my $builder = sub { \$(document).ready(function(){ \$("#$function_name").flatpickr({ + altInput: true, + altFormat: "$dateformat", + altInputClass: "input_marceditor flatpickr-input", dateFormat: "Y-m-d" }); /* Set current date on page load */ @@ -53,8 +63,10 @@ function Click$function_name(event) { function set_to_today( id, force ) { /* The force parameter is used in Click but not in Focus ! */ if (! id) { alert(_("Bad id ") + id + _(" sent to set_to_today()")); return 0; } - if (\$("#" + id).val() == '' || force ) { - \$("#" + id).val("$date"); + var elt = document.querySelector("#" + id); + if ( elt.value == '' || force ) { + const fp = document.querySelector("#" + id)._flatpickr; + fp.setDate(new Date()); } } -- 2.39.5