feat: add error messages aggregator #18
Closed
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 enhances antd-zod by introducing a customizable error aggregation mechanism. Instead of only returning a single error per field, developers now have control over how multiple error messages are combined using a new option:
aggregateErrorMessages.Changes
New Option:
aggregateErrorMessages(prev: string, next: string) => stringthat defines how to combine error messages for the same field.Refactored Modules
createSchemaFieldRule.tsaggregateErrorMessagesoption.validateFieldsduring rule creation.validateFields.tsaggregateErrorMessagesoption toformatErrors.formatErrors.tsaggregateErrorMessagesfunction.Test Updates
createSchemaFieldRule,validateFields, andformatErrorsto supply the new option.formatErrors.test.tsto verify that different aggregation strategies work as expected:Motivation
This change addresses a common need where developers want more control over error message presentation in forms. Previously, antd-zod only returned one error per field, which limited flexibility. With the new aggregation option, developers can tailor the error display—whether that means showing all errors concatenated or just the primary error—thereby improving the user experience in form validations.
Impact
(prev, next) => prev).Looking forward to your feedback!