Bug 32949 - Smart-rules prefills junk date on page load
Summary: Smart-rules prefills junk date on page load
Status: Failed QA
Alias: None
Product: Koha
Classification: Unclassified
Component: System Administration (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low normal
Assignee: Peter Vashchuk
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-13 13:51 UTC by Peter Vashchuk
Modified: 2023-02-20 22:49 UTC (History)
1 user (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 32949: Do not fill form with wrong shadow value to avoid data loss in smart-rules.tt (3.14 KB, patch)
2023-02-13 14:15 UTC, Peter Vashchuk
Details | Diff | Splinter Review
Bug 32949: Do not fill form with wrong shadow value to avoid data loss in smart-rules.tt (3.21 KB, patch)
2023-02-13 15:51 UTC, Owen Leonard
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Vashchuk 2023-02-13 13:51:06 UTC

    
Comment 1 Owen Leonard 2023-02-13 13:53:21 UTC
What is a junk date? How do you reproduce this bug?
Comment 2 Peter Vashchuk 2023-02-13 14:15:05 UTC
Created attachment 146584 [details] [review]
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.
Comment 3 Peter Vashchuk 2023-02-13 14:21:27 UTC
(In reply to Owen Leonard from comment #1)
> What is a junk date? How do you reproduce this bug?

Hey Owen, I already had a fix for it, was meant to push it asap after I created this bug, please see the patch and description of it for more info.
Comment 4 Owen Leonard 2023-02-13 15:51:34 UTC
Created attachment 146587 [details] [review]
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.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Comment 5 Katrin Fischer 2023-02-20 22:48:57 UTC
I don't have the patch applied, but I can't reproduce the issue.

I also tried using another date format, but it all behaves nicely:

* Set dateformat to DD.MM.YYYY
* Create a circulation rule ALL-ALL-Books, with 21.2.2023 as hard due date and auto-renewal before.
* Save rule.
* Edit rule and save without changes.
* Edit rule again - dates are still correct.

Tested on master as of today. Also with the standard format MM.DD.YYYY.

Can you please have a look?