Repository navigation
Fix server-side validation errors as string arrays not being displayed - #11447
Open
shondsouza wants to merge 1 commit into
Open
shondsouza wants to merge 1 commit into
shondsouza wants to merge 1 commit into
Conversation
APIs such as Django REST Framework return a list of messages per field. setSubmissionErrors treated those lists as ArrayInput items, so the input turned red without showing any text. Null or undefined values also made it crash. Closes marmelab#8278.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Many APIs return server-side validation errors as a list of messages per field. Django REST Framework is one example:
{ "errors": { "title": ["The title is too short", "The title must be unique"] } }setSubmissionErrorstreated those lists as<ArrayInput>items and set errors ontitle.0andtitle.1. Thetitleinput turned red but showed no message (#8278).The same function also crashed with
TypeError: Cannot convert undefined or null to objectwhen a field's value wasnull, and crashed when it wasundefined. For example,{ title: 'Required', body: null }triggers it.Solution
In
setSubmissionErrors:nullandundefinedvalues, and empty arrays, are ignored.<ArrayInput>item errors, as before.Trade-off: an
<ArrayInput>holding scalar items, e.g.tags: ['', 'bad tag'], now gets one combined error ontagsinstead of one error per item. Mixed arrays (strings and objects) keep the previous behaviour.How to test
setSubmissionErrors.spec.ts. Three of them fail without the fix, including the null crash.Form / ServerSideValidationWithMessageArraysand a matching test inForm.spec.tsx.docs/Validation.mdanddocs_headless/.../Validation.md.Closes #8278