Skip to content

How to clear inputs on successful submission #169

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

You must be logged in to vote

It looks like there is a regression from 0.6.2 on how defaultValue is handled 🤦🏼 .

For now, please do this:

const [form, fields] = useForm({
    id: "some-id",
    ref: formRef,
    // Note 1: You should use getFieldsetConstraint(schema) instead
    constraint: schema,
    // Note 2: Pass the last submission only if the action is not successful
    lastSubmission: !actionData?.success ? actionData?.submission : undefined,
    onValidate({ formData }) {
      return parse(formData, { schema: schema });
    },
    shouldRevalidate: "onBlur",
});

This is just a temporary fix. I will make sure this is fixed on the next version.

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
4 replies
@MoSattler
Comment options

@edmundhung
Comment options

Answer selected by MoSattler
@MoSattler
Comment options

@edmundhung
Comment options

Comment options

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

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