astro-reactive icon indicating copy to clipboard operation
astro-reactive copied to clipboard

feat(form): work with popular schema builders

Open ayoayco opened this issue 3 years ago • 10 comments
trafficstars

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} />

ayoayco avatar Oct 17 '22 08:10 ayoayco

Check zod-form-data https://www.npmjs.com/package/zod-form-data

ayoayco avatar Oct 17 '22 11:10 ayoayco

remix-validated-form https://www.remix-validated-form.io

ayoayco avatar Oct 17 '22 13:10 ayoayco

@ayoayco I will try to implement this. Seems interesting.

fazzaamiarso avatar Jan 10 '23 20:01 fazzaamiarso

There are other popular schema builders like yup but zod seems a good start

ayoayco avatar Jan 10 '23 20:01 ayoayco

It's set then, I also most familiar with zod

fazzaamiarso avatar Jan 10 '23 20:01 fazzaamiarso

Yup let's go with zod first 😁

ayoayco avatar Jan 10 '23 21:01 ayoayco

@fazzaamiarso one thing to note is that importing Validators here is important. It ensures the Validator.astro

ayoayco avatar Jan 11 '23 18:01 ayoayco

@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 avatar Mar 06 '23 17:03 fazzaamiarso

@fazzaamiarso Awesome! Thanks for the update! This is one of the most exciting features for our library

ayoayco avatar Mar 06 '23 18:03 ayoayco

@fazzaamiarso Awesome! Thanks for the update! This is one of the most exciting features for our library

ayoayco avatar Mar 06 '23 18:03 ayoayco