Skip to content

Validation on Blur Fires the Form's onSubmit - Is that expected? #870

Answered by chimame
kevinhpage asked this question in Q&A
Discussion options

You must be logged in to vote

Do you want to handle onSubmit after validating the data? If so, is this what you want to do?
https://conform.guide/api/react/useForm#options

const Test => {
  const [form, fields] = useForm({
    lastResult,
    shouldValidate: 'onBlur',
    onValidate({ formData }) {
      return parseWithZod(formData, { schema: schema });
    },
    onSubmit(e) {
      console.log('onSubmit', e);
    }
  });

  return (
    <Form id={form.id} method="post" onSubmit={form.onSubmit}>
      <TextField label='Field 1' name={fields.field1.name} />
      <TextField label='Field 2' name={fields.field2.name} />
      <Button type="submit">Submit</Button>
    </Form>
  );
};

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@kevinhpage
Comment options

Answer selected by kevinhpage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants