feat: add multiple errors #19
Merged
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.
This PR refactors the error formatting in antd-zod so that multiple validation errors for a given field are returned as arrays of strings rather than a single concatenated error message. This change improves flexibility and allows consumers to display all errors separately.
Changes
1.
formatErrors.ts
Instead of accumulating a single string per field, error messages are now collected into an array.
2.
validateFields.ts
The function now returns a promise resolving to an object with error messages as string arrays (
{ [key: string]: string[] }
).3.
createSchemaFieldRule.ts
Tests have been updated to expect rejection with an array of errors (e.g.,
["Required"]
).4. Tests
formatErrors
,validateFields
, andcreateSchemaFieldRule
have been updated to account for the new error array format.{ field: ["Required"] }
instead of a single string.Motivation
Returning errors as arrays provides better control and allows for more flexible UI designs.
Updated tests and a Storybook example ensure clarity and proper usage of the new error format.
Impact
Consumers of antd-zod can now choose to display multiple errors separately in any format they prefer.
Thank you for reviewing this PR. I look forward to your feedback and suggestions!