TanStackT
TanStack7mo ago
9 replies
popular-magenta

form.state.isValid/ isFormValid / isFieldsValid is true, form.state.errors is empty, zod schema

Hello, I am trying to disable the save button of a form when the description field is empty. I guess I have to use either form.state.isValid or .isFormValid or isFieldsValid, any of the three options 😵‍💫 but they are always true, even when I see the zod validation error

My form:
  const form = useForm({
    defaultValues: {
       ...
    },
    onSubmit: async ({ value: partFormData }) => {
      try {
        if (createPart) {
          const { id, ...newPartData } = partFormData;
          await onSave(newPartData);
        } else {
          await onSave(partFormData);
        }
        return { status: "success" };
      } catch (error) {
        const errorDescription = error instanceof Error ? error.message : "Error desconocido";
        toast.error("Error al guardar el artículo", {
          description: errorDescription,
        });
        return { status: "error", message: errorDescription };
      }
    },
  });
image.png
Was this page helpful?