open-formulieren / open-forms-sdk

A Javascript SDK for Open Forms
https://open-forms.readthedocs.io/en/stable/developers/sdk/index.html
Other
2 stars 6 forks source link

[open-formulieren/open-forms#4158] Fix date validation and translations #671

Closed Viicos closed 3 months ago

Viicos commented 4 months ago

Fixes open-formulieren/open-forms#4158

This fixes two things:

Lots of test failing so I'll wait for a review before tackling these.

sergei-maertens commented 4 months ago

The new Date -> parseIso patch needs to be backported

Viicos commented 4 months ago

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)

codecov[bot] commented 3 months ago

Codecov Report

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.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #671 +/- ## ========================================== - Coverage 63.64% 61.56% -2.08% ========================================== Files 93 224 +131 Lines 1642 4106 +2464 Branches 427 836 +409 ========================================== + Hits 1045 2528 +1483 - Misses 597 1460 +863 - Partials 0 118 +118 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Viicos commented 3 months ago

This is how it looks with the format options:

image