Repository navigation
fix: invalid date in a DateTime-bound Datepicker no longer crashes the app - #4413
Conversation
Typing an impossible date like 32.13.2026 into a Datepicker bound to a DateTime field sent the raw text in the PATCH. The backend could not deserialize it and the frontend crashed with "Ukjent feil". convertData now rejects values that are not ISO dates (strictParseISO) for string fields with format date or date-time, so they are kept as invalid data and never sent. The Datepicker reads the invalid value to show its own "invalid date format" message, and filters out the generic invalid-data message to avoid a duplicate. Refs #4180
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Studio generates a C# DateTime only for format date-time. For format date it generates a string that accepts any text, so validating it would stop saving the text without preventing any crash.
|
✅ Automatic backport successful! A backport PR has been automatically created for the The release branch The cherry-pick was clean with no conflicts. Please review the backport PR when it appears. |
Summary
Leaving a Datepicker bound to a
DateTimefield with text it can't parse no longer crashes the app. That includes an impossible date (32.13.2026) and, more commonly, an unfinished one (12.12, saved as12.12.____). The user now gets the Datepicker's own "invalid date format" message, and the invalid text is never sent to the backend.Datepicker blur("32.13.2026") setLeafValue convertData(value, schema) # src/features/formData/convertData.ts - type: string → accept anything + type: string + format: date-time + !strictParseISO(value) → error - → currentData → PATCH → backend 500 → "Ukjent feil" error page + → invalidCurrentData (kept in the field, never sent) useDatepickerValidation # src/layout/Datepicker/useDatepickerValidation.ts - reads saved value only + reads saved value ?? invalid value → "Ugyldig datoformat. Bruk formatet DD.MM.YYYY." Datepicker.getValidationFilters # src/layout/Datepicker/index.tsx + drop InvalidData 'validation_errors.pattern' (duplicate of the message above)This reuses the existing invalid-data mechanism, the same one that already handles e.g.
-typed into a number field.Only
format: date-timeis checked. Studio generates a C#DateTimefordate-timefields, so the backend can't store text that isn't a date. Forformat: dateit generates astring, which stores any text, so those fields can't cause this crash and are left unchanged.Evidence
A v8 app (Altinn.App 8.12.15) in localtest, with a Datepicker bound to
DateTime? dato("type": "string", "format": "date-time"). Type32.13.2026, then leave the field.replace /dato "32.13.2026"→ 500 → error page.After (this branch): the invalid text is not sent, and the form stays usable with one validation message.
Unfinished date (
12.12), same app:replace /dato "12.12.____"→ 500 → the same error page.Tests (both fail on
mainand pass on this branch):yarn tscandyarn lintpass. The Jest suites for formData, validation, Datepicker, Input and datamodel all pass.Merge Danger
Door: two-way
Frontend only, with no data migration. Reverting restores the old behaviour.
Blast Radius: date-time fields
format: date-time, not just the Datepicker. Text that isn't an ISO date is now kept as invalid data instead of being sent.strictParseISO(date-fns) is a bit more lenient than .NET'sSystem.Text.Json. Rare ISO forms the Datepicker can't produce (week dates like2026-W01-1, a space instead ofT) still reach the backend and still crash the app.Follow-up (not in this PR):
FormDataWriteProviderthrows every save error to the error boundary (if (error) throw error;). Handling a 4xx from PATCH without crashing would also cover the rare forms above.Related Issue(s)
Verification/QA
kind/*andbackport*label to this PR for proper release notes groupingSummary by CodeRabbit