Skip to content

How can we lock (disable) the submit button while action is being executed? #790

Answered by edmundhung
tats-u asked this question in Q&A
Discussion options

You must be logged in to vote

Conform is designed to handle validation only and will prevent form submission if validation fails. However, the actual submission is left to the Remix <Form> component, which differs from RVF’s approach.

To disable the submit button while validation passes and the action is running, you can use Remix’s useNavigation or useFetcher to monitor the submission state:

import { Form, useNavigation } from "@remix-run/react";

function MyForm() {
  const navigation = useNavigation();
  const isSubmitting = navigation.state === "submitting";

  return (
    <Form method="post">
      {/* form fields */}
      <button type="submit" disabled={isSubmitting}>
        Submit
      </button>
    </Form>
  

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@tats-u
Comment options

@brunobely
Comment options

@tats-u
Comment options

@brunobely
Comment options

Answer selected by tats-u
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