astro-reactive
astro-reactive copied to clipboard
feat(form): work with popular schema builders
Idea:
---
import Form, { FormGroup } from "@astro-reactive/form";
import { Validators } from "@astro-reactive/validator";
import * as z from 'zod';
const schema = z.object({
username: z.string().min(1),
email: z.string().email().min(1),
password: z.string().min(8);
});
const form = new FormGroup.from(Validators.zod, schema);
---
<Form formGroups={form} />
Check zod-form-data https://www.npmjs.com/package/zod-form-data
remix-validated-form https://www.remix-validated-form.io
@ayoayco I will try to implement this. Seems interesting.
There are other popular schema builders like yup but zod seems a good start
It's set then, I also most familiar with zod
Yup let's go with zod first 😁
@fazzaamiarso one thing to note is that importing Validators here is important. It ensures the Validator.astro
@ayoayco started working on this today and successfully implement zod schema to FormGroup. It's still have minimal functionality and typings is a mess.
I take the resolvers approach from react-hook-form, so we can plug any resolver we want. Just need a uniform return type from each resolvers.
Just wanted to let you know! 😁
@fazzaamiarso Awesome! Thanks for the update! This is one of the most exciting features for our library
@fazzaamiarso Awesome! Thanks for the update! This is one of the most exciting features for our library