TanStackT
TanStack11mo ago
17 replies
colossal-harlequin

How to set submit as disabled until form completed?

I have a basic form. 2 fields.

Right now I'm doing the following to set the submit as disabled on page load.

<form.Subscribe
        selector={(state) => [state.canSubmit, state.isSubmitting, state.isPristine]}
        children={([canSubmit, isSubmitting, isPristine]) => (
            <Button
              fullWidth
              disabled={isPristine || !canSubmit}
              color="green"
              type="submit"
              leftSection={<Icon icon="save" type="far" />}
              loading={isSubmitting as boolean}
            >
            Login
          </Button>
        )}
      />


Problem is. When I complete the first field. The submit will be enabled.

The UX that I'm looking for. Is that I only want the submit button to be enabled only when both fields have passed validation.

Is this possible? Thanks!
Screenshot_2025-03-11_at_09.49.03.png
Was this page helpful?