From df34fb4fcb2e6c567089819545d203d809173063 Mon Sep 17 00:00:00 2001 From: Petro Vashchuk Date: Sat, 8 Oct 2022 15:09:09 +0300 Subject: [PATCH] Bug 32949: Do not fill form with wrong shadow value to avoid data loss in smart-rules.tt When you edit the rule without initializing flatpickr plugin, if you press the save button it will overwrite the date with an empty value, making you lose the dates. This happens because flatpickr plugin's shadow value is not loaded if it's not initialized with a click on that date field. This patch fixes it. 1st Code commit text: To reproduce: 1. Head over to the smart rules admin page and create/use existing rule for certain item type/category. 2. Set "hard due date" and "No automatic renewal after (hard limit)" of that rule to a certain date and save. 3. Edit that same rule again, but this time just save it without any changes. The data for hard due date and hard limit will get lost and will be set as "None defined". 4. Apply the patch. 5. Repeat steps 2 and 3. Ensure that the data loss is not happening anymore. --- .../intranet-tmpl/prog/en/modules/admin/smart-rules.tt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt index 2fba8747e4..caf98393c4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -1484,13 +1484,18 @@ }else { input_value = itm.split(' ')[1]; } - $(current_column).find("input[type='text']").val(input_value); + const fp = $(current_column).find("input.flatpickr").get(0)._flatpickr; + fp.setDate(input_value, true, '[% IF ( dateformat == "us" ) %]m/d/Y[% ELSIF ( dateformat == "metric" ) %]d/m/Y[% ELSIF ( dateformat == "dmydot" ) %]d.m.Y[% ELSE %]Y-m-d[% END %]'); $(current_column).find("select").val(select_value); } else if ( i == 16 ) { // specific processing for cap_fine_to_replacement_price var cap_fine_to_replacement_price = $(this).find("input[type='checkbox']"); $('#cap_fine_to_replacement_price').prop('checked', cap_fine_to_replacement_price.is(':checked') ); $('#overduefinescap').prop('disabled', cap_fine_to_replacement_price.is(':checked') ); + } else if ( i == 25 ) { + // specific processing for the hard limit for the automatic renewal after + const fp = $(current_column).find("input.flatpickr").get(0)._flatpickr; + fp.setDate(itm, true, '[% IF ( dateformat == "us" ) %]m/d/Y[% ELSIF ( dateformat == "metric" ) %]d/m/Y[% ELSIF ( dateformat == "dmydot" ) %]d.m.Y[% ELSE %]Y-m-d[% END %]'); } else { $(current_column).find("input[type='text']").val(itm); // select the corresponding option -- 2.38.1