json scheme
Hello,
We want to replace a form builder we are using with TS form.
1- How can we implement json scheme support?
2- can these libraries help, or is there a simpler implementation?
- https://github.com/StefanTerdell/zod-to-json-schema
- https://github.com/StefanTerdell/json-schema-to-zod
The plan is after we find the scheme we use this lib to generate the ui. https://github.com/vantezzen/auto-form
4 Replies
helpful-purple•2y ago
Hmm, I'm not 100% sure I understand your use case.
You want to use JSON schema for the form type validation and such, which makes sense, and TS Form can help with that. If you want, I can walk you through making a PR for this feature.
However, I'm not sure if TS Form and AutoForm will play well together, not to mention that the json-schema-to-zod library heavily discourages it be used at runtime since you would need to use the dangerous
eval()
method.
If you are just using json-schema-to-zod at build time to generate the zod schema, then you can run it through auto-form and get your form, and I can't think of a way to get it to work with TS Form in a remotely ergonomic way. Is there a TS Form feature specifically that you need?unwilling-turquoiseOP•2y ago
Hello @aadit thanks a lot for the replay. Our use-case is to create a form using UI, then store it in the database as jsonscheme and show it in the front-end. Please share any resource on how to make this (per your point in first part) and consider this issue resolved.
helpful-purple•2y ago
Ok I see. I'll be honest, I don't think TS Form will be a good fit here. TS Form works best when you know what fields you have ahead of time. In this case, your form is completely dynamic
I think this (https://jsonforms.io/) might suit your needs better. You won't have to do a janky conversion to Zod, you can just use your Json schema directly. The only caveat is, you will have to define and store a UI schema as well, which will tell the form builder how to display your form.
More forms. Less code. - JSON Forms
More forms. Less code.
unwilling-turquoiseOP•2y ago
Thanks a lot.