TanStackT
TanStack3y ago
31 replies
still-lime

how to disable submit button initially?

Apparently, canSubmit is
true
initially even if e.g. mandatory fields are empty, because no field validation happened yet.

I tried using defaultState like this, but it did not work:

 const form = useForm({
    defaultValues: {
      firstName: "",
      lastName: "",
    },
    defaultState: {
      canSubmit: false,
    },
    onSubmit: async (values) => {
      console.log(values);
    },
  });


I can disable my submit button using something like disabled={!(isTouched && canSubmit)} but is there a "better" way?
Was this page helpful?