Closed Viicos closed 3 months ago
The new Date
-> parseIso
patch needs to be backported
Following https://github.com/open-formulieren/open-forms-sdk/pull/671#discussion_r1567504978:
For the date
and datetime
component, the wanted behavior is (assuming only a minDate
constraint was set):
If there is a custom error message for the minDate
error key, use it.
Else if there is a custom error message for the invalid_date(time)
error key, use it. Note that these two error keys do not exist yet, although invalid_date
seems to already exist in Formio. These two PRs:
adds support for it.
Else, use "minDate"
as an error message (this is counter intuitive, but Formio can handle both error keys and messages when passed to the translation function); default Formio translations will apply.
Note that min/maxDate
validate constraints are used for both the date
and datetime
component. This isn't really an issue if custom translations are provided. That is with the following configuration:
{
"type": "datetime",
"key": "my_cmp",
"validate": {
"minDate": "2020-01-01T00:00:00"
},
"translatedErrors": {
"en": {
"minDate": "Datetime should be greater than ..." // Message specific to datetimes
}
}
}
However, if we don't provide a custom error message for the minDate
error key, it will default to a "generic" one from Formio (and will not say anything about time)
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 61.56%. Comparing base (
5646fa5
) to head (e62c0d8
). Report is 30 commits behind head on main.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
This is how it looks with the format options:
Fixes open-formulieren/open-forms#4158
This fixes two things:
Adone in https://github.com/open-formulieren/open-forms-sdk/pull/673date
component withminDate
set would not validate properly (e.g. withminDate=2024-01-01
,2024-01-01
would fail to validate). This is fixed by switching fromnew Date(minBoundary)
toparseISO(minBoundary)
.validateBoundaries
to only return one possible error key, although we might want to follow what is done in thetime
component at some point (seeMinMaxTimeValidator.js
;invalid_time
is a valid error key, and it will fallback to the provided message ofinvalid_time
ifminTime
doesn't have a custom message).Lots of test failing so I'll wait for a review before tackling these.