Bug 27768 - Flatpickr allows entering invalid dates (from cataloguing plugin dateaccessioned.pl)
Summary: Flatpickr allows entering invalid dates (from cataloguing plugin dateaccessio...
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: Cataloging (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal (vote)
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-24 02:36 UTC by Phil Ringnalda
Modified: 2023-03-05 18:03 UTC (History)
2 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Phil Ringnalda 2021-02-24 02:36:27 UTC
Steps to reproduce:

1. Edit any item, change either the "d - Date acquired" or "w - Price effective from" to anything not-a-date (I like 24.99, due to mispasting Replacement price into Price effective from
2. Save the record

Actual result:

Invalid value passed, items.replacementpricedate=2 expected type is date at /usr/share/perl5/Exception/Class/Base.pm line 88

You can hit Back in the browser to go back and fix it, assuming you know what an items.replacementpricedate is or have an English speaker handy to tell you it's the Дата, для якої чинна ціна заміни.

Expected result:

Human readable message in a popup or in the page itself, giving the name of the field in the editor, rather than the name of the field in the database
Comment 1 Katrin Fischer 2021-06-04 09:42:30 UTC
I haven't been able to replicate the problem on 21.05/master, but when you enter an invalid date there is no error at all now. 

The date widget only shows for $d Date acquired, but it would be nice if it showed for the other fields as well. Maybe we could detect the data type in the database or we could add an option to the frameworks to say "is a date".

Instead when you open the record again, it shows as 0000-00-00. So there are still some changes needed to have a helpful error message.
Comment 2 Marcel de Rooy 2022-04-28 09:18:51 UTC
Current master as of today:

Trying to save 24.99 does no longer work.
Trying to save free text like 'test' does not work.

An empty field results in date of today in record (no problem).

But unfortunately I can still get 0000-00-00 into my records by entering 0000-00-00 into the date field. It is displayed by the date picker as 00-1-11-30 (meaning: November 30 of year -1 ??) but gets stored as 0000-00-00.

Also note: I can also save 0000-01-01. Or 0001-01-01, 0002-02-01, etc. Years like 0001 are displayed in the date picker as 1901 ?
Comment 3 Marcel de Rooy 2022-04-28 09:46:38 UTC
(In reply to Marcel de Rooy from comment #2)
> Current master as of today:
> 
> Trying to save 24.99 does no longer work.
> Trying to save free text like 'test' does not work.
> 
> An empty field results in date of today in record (no problem).
> 
> But unfortunately I can still get 0000-00-00 into my records by entering
> 0000-00-00 into the date field. It is displayed by the date picker as
> 00-1-11-30 (meaning: November 30 of year -1 ??) but gets stored as
> 0000-00-00.
> 
> Also note: I can also save 0000-01-01. Or 0001-01-01, 0002-02-01, etc. Years
> like 0001 are displayed in the date picker as 1901 ?

https://github.com/flatpickr/flatpickr/issues/1524
Comment 4 Jonathan Druart 2022-04-28 10:01:53 UTC
(In reply to Marcel de Rooy from comment #2)
> But unfortunately I can still get 0000-00-00 into my records by entering
> 0000-00-00 into the date field. It is displayed by the date picker as
> 00-1-11-30 (meaning: November 30 of year -1 ??) but gets stored as
> 0000-00-00.

I don't recreate that, I am getting a 500 with

Invalid value passed, dateaccessioned=00-1-11-30 expected type is date at /usr/share/perl5/Exception/Class/Base.pm line 88
Comment 5 Marcel de Rooy 2022-04-28 12:00:28 UTC
(In reply to Jonathan Druart from comment #4)
> I don't recreate that, I am getting a 500 with
> 
> Invalid value passed, dateaccessioned=00-1-11-30 expected type is date at
> /usr/share/perl5/Exception/Class/Base.pm line 88

Set sql mode to 0. Assuming that this still is the case for a regular install.
Comment 6 Phil Ringnalda 2023-03-05 18:03:12 UTC
What I filed this on, the case where you have a date field for items which doesn't use the dateaccessioned plugin, is unchanged. You can enter a non-date, and we throw an unhelpful error.

 "Flatpickr doesn't let you enter an invalid date unless you work really hard at it" only answers that issue if instead of making its use a default (that can be changed), only in new installs, we make item date fields the only bib framework fields where you cannot change the plugin used.