Skip to content

Track isSubmitted and isValid state client-side #321

Answered by edmundhung
aust1nz asked this question in Q&A
Discussion options

You must be logged in to vote

There is no built-in state for these at the moment but we will have them supported very soon as you found :)

What you have above looks valid to me. But be aware that onSubmit is called only if there is no error, so if your consider the form submitted regardless there is any error, you can do this instead:

const [form, fields] = useForm({
    lastSubmission,
    shouldValidate: "onBlur",
    onValidate({ formData }) {
      const parsed = parse(formData, { schema });
      setValid(Object.keys(parsed.error).length === 0);
      if (parsed.intent === 'submit') setSubmitted(true);
      return parsed;
    },
  });

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@aust1nz
Comment options

@Pouet--
Comment options

@aust1nz
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

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

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