-
-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: return an array of errors from a single validator (custom & schema library) #1090
base: main
Are you sure you want to change the base?
feat: return an array of errors from a single validator (custom & schema library) #1090
Conversation
Allow string and string[] as returned value from validator but always set string[] on error maps
View your CI Pipeline Execution ↗ for commit 86c9943.
☁️ Nx Cloud last updated this comment at |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1090 +/- ##
==========================================
+ Coverage 86.60% 88.43% +1.83%
==========================================
Files 29 29
Lines 1172 1159 -13
Branches 287 281 -6
==========================================
+ Hits 1015 1025 +10
+ Misses 144 124 -20
+ Partials 13 10 -3 ☔ View full report in Codecov by Sentry. |
This PR addresses the frequent request of being able to return multiple errors from a single validator.
Validator functions (aka what you put inside
validators: { onChange: () => ... }
) can now return aValidationResult
that isundefined | false | null | ValidationError | ValidationError[]
withValidationError
being astring
.Existing validators returning a single string will keep working, additionally you can now also return an array of strings.
As a side effect, validators defined with schema libraries will no longer be cut to the first error by default, but all errors will be shown instead.
Breaking Changes
Being able to return an array of strings from a validator means
errorMap.onChange
& co will no longer be a string but an array.Documentation has been updated showing the quickest change to keep the previous behaviour:
In case you were using
meta.errors
to display all your errors there won't be any breaking change since this value will always be a (flat) aggregate array of errors.Feedback is welcome!