Comments (10)
Ok, glad to know that it's in the back of your head for the future! I hope it is doable, as said the alternative is to make a schema standard, so introspection can be made independent of library, and adapters for each library to transform the schema to the library-specific one.
from valibot.
Hey, with Modular Forms, my own form library, I had decided to rely on adapters for schema validation. This makes it theoretically possible to connect any validations library. This approach also has the smallest footprint in bundle size, as only the adapter that is used ends up in the bundle. The adapter basically only maps the errors into a uniform structure for the form library.
For example, here is the code of the valiForm
adapter: https://github.com/fabian-hiller/modular-forms/blob/main/packages/react/src/adapters/valiForm.ts
from valibot.
That looks like the approach that typeschema is taking, which works in the relatively simple case of schema validation - error mapping. But schema introspection, its requirements and specification, goes beyond that. It needs to be supported by the library, since we build the schemas directly in them.
This per-library DSL causes the fragmentation I'm mentioning in the typeschema issue. So either an agnostic schema definition must be used, which can be adapted or directly supported by each library, or a validation library must support introspection according to some specification. I'm hoping for the latter, since the schema definition belongs to the library.
Given the number of JS validation libraries it's obviously quite easy (or maybe fun, challenging, interesting enough) to create one and deploy it into the wild, but it also should assume some responsibility regarding the above. Otherwise, Zod is the only option I have for Superforms.
from valibot.
I haven't quite understood why the approach I use with Modular Forms doesn't work for Superforms. Modular Forms supports Zod and Valibot in this way and allows you to connect any other library. Maybe you can make a code example.
I know that React Hook Form uses resolvers
, which is probably the same as Modular Forms under a different name.
from valibot.
Here you can find a code example with Modular Forms: https://modularforms.dev/react/guides/validate-your-fields#schema-validation
In fact, with Qwik this approach works so well that the same scheme can be used for validation in the browser and on the server, and everything works even if JavaScript is disabled in the browser: https://modularforms.dev/qwik/guides/enhanced-forms
from valibot.
It works, but that's just the validation itself - a rather simple interface that typeschema is unifying for many other libraries as well. But since every validation library also locks consumers into their DSL (the schema definition), the need for introspecting this schema becomes important when you're using it in form validation, for example. This is what I'm discussing here: decs/typeschema#9
Is there any schema introspection available for Valibot that covers these cases?
from valibot.
I have read through your posts and understand what you mean. No, this approach is currently not possible with Valibot. This is due to the fact that a schema in Valibot is composed of different functions and Valibot does not collect validation information about them in advance.
However, I believe it would be technically possible. However, it would increase the bundle size and make the source code more complex. Currently I don't know if this is a functionality I want to support with Valibot. However, I am keeping it in mind as this functionality would also allow serializing a schema in JSON.
from valibot.
Issue is related to: #23
from valibot.
Hey 👋 I think when #211 is merged Valibot will support the functionality you asked for.
from valibot.
v0.21.0 is now available. Presumably not everything is perfect yet. So please let us know if you have any ideas for improvements.
from valibot.
Related Issues (20)
- `isoTimestamp` only accepts UTC timestamps HOT 3
- Not able to validate file uploads on the backend, even though it works on the frontend HOT 4
- Search fails to work HOT 1
- Timestamp regex doesn't support timezone other than Zulu HOT 1
- Can't use Valibot with H3 Data validation HOT 6
- optional string field with string min/max options set wrong meta in veevalidate HOT 2
- How to conditionally require object with all its fields HOT 2
- `<select>` custom validation inside a `variant` schema HOT 4
- Function to support for json type HOT 2
- Number literal don't trigger variant validation HOT 7
- `_addIssue` blocks `every`, `some` & `check` actions rewrite due to a possible type issue HOT 2
- Email regex pattern does not allow all valid characters HOT 1
- Are there any similarities about zod `.superRefine`? HOT 1
- Error when building HOT 6
- How to access other field? HOT 2
- Allow null default value while enforcing required validation HOT 2
- Force typeing on object schema HOT 2
- Investigate memory, performance and bundle size impact when caching basic schema objects
- Conditionally validate HOT 2
- Not correct lang after set globally lang HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from valibot.