[feat] Field validation from form schema
This PR introduces the ability to pass a schema to the validators object on a form and have it validate each specific field:
const form = useForm({
defaultValues: {
firstName: '',
lastName: '',
},
onSubmit: async ({ value }) => {
// Do something with form data
console.log(value)
},
validators: {
onChange: z.object({
// Errors here are passed to the <form.Field name="firstName"> component
firstName: z.string().min(3, 'First name must be at least 3 characters'),
lastName: z.string().min(3, 'Last name must be at least 3 characters'),
}),
},
// Add a validator to support Zod usage in Form and Field
validatorAdapter: zodValidator({}),
})
TODO
- [ ] Update Valibot adapter
- [x] Update Yup adapter
- [ ] Update docs
โ๏ธ Nx Cloud Report
CI is running/has finished running commands for commit 198c08a2937744e2fbbe944a06e459065a5437b4. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.
๐ See all runs for this CI Pipeline Execution
โ Successfully ran 2 targets
Sent with ๐ from NxCloud.
More templates
- @tanstack/form-example-angular-array
- @tanstack/form-example-angular-simple
- @tanstack/form-example-angular-valibot
- @tanstack/form-example-angular-yup
- @tanstack/form-example-angular-zod
- @tanstack/form-example-lit-simple
- @tanstack/form-example-lit-ui-libraries
- @tanstack/form-example-react-array
- @tanstack/field-errors-from-form-validators
- @tanstack/form-example-react-next-server-actions
- @tanstack/form-example-react-query-integration
- @tanstack/form-example-react-tanstack-start
- @tanstack/form-example-react-simple
- @tanstack/form-example-react-valibot
- @tanstack/form-example-react-ui-libraries
- @tanstack/form-example-react-yup
- @tanstack/form-example-react-zod
- @tanstack/form-example-solid-array
- @tanstack/form-example-solid-simple
- @tanstack/form-example-solid-yup
- @tanstack/form-example-solid-valibot
- @tanstack/form-example-solid-zod
- @tanstack/form-example-vue-array
- @tanstack/form-example-vue-simple
- @tanstack/form-example-vue-valibot
- @tanstack/form-example-vue-yup
- @tanstack/form-example-vue-zod
@tanstack/form-core
pnpm add https://pkg.pr.new/@tanstack/form-core@925
@tanstack/angular-form
pnpm add https://pkg.pr.new/@tanstack/angular-form@925
@tanstack/lit-form
pnpm add https://pkg.pr.new/@tanstack/lit-form@925
@tanstack/react-form
pnpm add https://pkg.pr.new/@tanstack/react-form@925
@tanstack/solid-form
pnpm add https://pkg.pr.new/@tanstack/solid-form@925
@tanstack/valibot-form-adapter
pnpm add https://pkg.pr.new/@tanstack/valibot-form-adapter@925
@tanstack/vue-form
pnpm add https://pkg.pr.new/@tanstack/vue-form@925
@tanstack/yup-form-adapter
pnpm add https://pkg.pr.new/@tanstack/yup-form-adapter@925
@tanstack/zod-form-adapter
pnpm add https://pkg.pr.new/@tanstack/zod-form-adapter@925
commit: 198c08a
Yep I was going to try to contribute here and was waiting for the field error set from form PR to be merged. I'm happy to give feedback and try it out at least.
What is the current status of this PR?
@bompi88 I'm... Actively working on it? Like, have made commit less than an hour ago that marked a lot of things off?
We'll get it reviewed soon, but timing just felt weird with "status?" right after I'd worked on it lol
@crutchcorn I'm sorry I did not see that. I agree that is weird ๐
๐
This LGTM @Balastrong - great work! Merging now
@crutchcorn Nice work! I love to test it out ๐ I think the squash commit message was on the wrong format [feat] and not feat: therefore no release? I might be wrong here
@bompi88 you're right! :D
I fixed it now, 0.33 should be available ๐
Thanks @Balastrong and @crutchcorn ! So far this version works really well๐