Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(form): work with popular schema builders #99

Open
ayoayco opened this issue Oct 17, 2022 · 10 comments · May be fixed by #266
Open

feat(form): work with popular schema builders #99

ayoayco opened this issue Oct 17, 2022 · 10 comments · May be fixed by #266

Comments

@ayoayco
Copy link
Member

ayoayco commented Oct 17, 2022

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 ayoayco changed the title feature(form): work with popular schema builders feat(form): work with popular schema builders Oct 17, 2022
@ayoayco
Copy link
Member Author

ayoayco commented Oct 17, 2022

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

@ayoayco
Copy link
Member Author

ayoayco commented Oct 17, 2022

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

@fazzaamiarso
Copy link
Member

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

@fazzaamiarso fazzaamiarso self-assigned this Jan 10, 2023
@ayoayco
Copy link
Member Author

ayoayco commented Jan 10, 2023

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

@fazzaamiarso
Copy link
Member

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

@ayoayco
Copy link
Member Author

ayoayco commented Jan 10, 2023

Yup let's go with zod first 😁

@ayoayco
Copy link
Member Author

ayoayco commented Jan 11, 2023

@fazzaamiarso one thing to note is that importing Validators here is important. It ensures the Validator.astro <script> is shipped to the browser.

@fazzaamiarso
Copy link
Member

@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! 😁

@ayoayco
Copy link
Member Author

ayoayco commented Mar 6, 2023

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

1 similar comment
@ayoayco
Copy link
Member Author

ayoayco commented Mar 6, 2023

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

@fazzaamiarso fazzaamiarso linked a pull request Mar 7, 2023 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants