-
-
Notifications
You must be signed in to change notification settings - Fork 444
feat(form-core): add parseValueWithSchema()
stateless method
#1421
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(form-core): add parseValueWithSchema()
stateless method
#1421
Conversation
View your CI Pipeline Execution ↗ for commit a05f497.
☁️ Nx Cloud last updated this comment at |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1421 +/- ##
==========================================
+ Coverage 88.37% 88.52% +0.14%
==========================================
Files 28 28
Lines 1308 1316 +8
Branches 343 343
==========================================
+ Hits 1156 1165 +9
+ Misses 135 134 -1
Partials 17 17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Some name ideas:
|
|
fe34551
to
7036146
Compare
parseValueWithSchema()
stateless method
This is to be consistent with other methods that include the word Values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, I like how this is turning out!
6ebd00c
to
41bda55
Compare
That should cover the comments. Also added some type safety to not pass schemas that will set errors on non-existent fields. |
parseValueWithSchema()
stateless methodparseValueWithSchema()
stateless method
Since we don't pass a field to the method, the term shouldn't be included in the method name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a perfect PR and a really nice addition, thank you so much!
As of tanstack form
v1.4
, there are two ways to use standard schemas as validators:1. Pass directly
2. Create a callback and import
standardSchemaValidators
While more verbose, the second function allows you to combine standard schemas easily with other onChange validation a user may want on the same form / field.
There are some things to note about this:
value
is redundant, asformApi | fieldApi
would have access to itvalidationSource
is redundant, asformApi | fieldApi
can infer itstandardSchemaValidators
must be imported as a separate 'helper' file.Given some users may want to add more logic than just a schema to their validation (and based on the discussion in this discord post, I propose the following:
FormApi#getValidationIssuesFromSchema(schema: StandardSchemaV1)
FieldApi#getValidationIssuesFromSchema(schema: StandardSchemaV1)
Name is subject to change. Suggest alternatives!
Usage
This would allow users to customize their validation more while preserving the parsing that
standardSchemaValidators
does.Important
This method should be stateless. Users should have control over whether to return the issues or not.