Imperative submit
In this example, we trigger a submit as soon as the user enters 4 characters.
const schema = z.object({ token: z.string().length(4) })
export default () => (
<Form schema={schema}>
{({ Field, Errors, submit }) => (
<>
<Field
name="token"
onChange={(ev: React.ChangeEvent<HTMLInputElement>) => {
if (ev.target.value.length === 4) submit()
}}
/>
<Errors />
</>
)}
</Form>
)
Imperative submit
In this example, we trigger a submit as soon as the user enters 4 characters.
const schema = z.object({ token: z.string().length(4) })
export default () => (
<Form schema={schema}>
{({ Field, Errors, submit }) => (
<>
<Field
name="token"
onChange={(ev: React.ChangeEvent<HTMLInputElement>) => {
if (ev.target.value.length === 4) submit()
}}
/>
<Errors />
</>
)}
</Form>
)