Giter VIP home page Giter VIP logo

Comments (10)

ciscoheat avatar ciscoheat commented on May 14, 2024 4

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.

fabian-hiller avatar fabian-hiller commented on May 14, 2024

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.

ciscoheat avatar ciscoheat commented on May 14, 2024

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.

fabian-hiller avatar fabian-hiller commented on May 14, 2024

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.

fabian-hiller avatar fabian-hiller commented on May 14, 2024

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.

ciscoheat avatar ciscoheat commented on May 14, 2024

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.

fabian-hiller avatar fabian-hiller commented on May 14, 2024

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.

fabian-hiller avatar fabian-hiller commented on May 14, 2024

Issue is related to: #23

from valibot.

fabian-hiller avatar fabian-hiller commented on May 14, 2024

Hey 👋 I think when #211 is merged Valibot will support the functionality you asked for.

from valibot.

fabian-hiller avatar fabian-hiller commented on May 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.