const schema = z.object({
name: z.string(),
bio: z.string()
});
const CustomForm = () => {
const form = useForm({
defaultValues: {
name: "",
bio: "",
},
validators: {
onSubmit: schema
},
onSubmit: async ({ value }) => {
// do api request stuff
}
});
const onSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
e.stopPropagation();
form.handleSubmit();
}
return (
<form onSubmit={onSubmit}>
<form.AppField
name="name"
validators={{
onChangeAsyncDebounceMs: 300,
onChangeAsync: ({ value }) => {
if (!value.trim().length) return "Name is required";
return "";
},
}}
children={(field) => <field.TextField label="Name" />}
/>
{/* other input field */}
<form.AppForm>
<form.SubscribeButton />
</form.AppForm>
</form>
)
}
const schema = z.object({
name: z.string(),
bio: z.string()
});
const CustomForm = () => {
const form = useForm({
defaultValues: {
name: "",
bio: "",
},
validators: {
onSubmit: schema
},
onSubmit: async ({ value }) => {
// do api request stuff
}
});
const onSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
e.stopPropagation();
form.handleSubmit();
}
return (
<form onSubmit={onSubmit}>
<form.AppField
name="name"
validators={{
onChangeAsyncDebounceMs: 300,
onChangeAsync: ({ value }) => {
if (!value.trim().length) return "Name is required";
return "";
},
}}
children={(field) => <field.TextField label="Name" />}
/>
{/* other input field */}
<form.AppForm>
<form.SubscribeButton />
</form.AppForm>
</form>
)
}