Skip to content
Discussion options

You must be logged in to vote

Conform does not support setting error outside of onValidate at the moment. But you can adjust the validation logic dynamically:

import { conform, useForm } from "@conform-to/react"

export default function Example() {
  const buttonRef = useRef<HTMLButtonElement>(null);
  const [form, fields] = useForm({
    onValidate({ formData }) {
       // dynamically update the validation logic based on the condition
    },
  })

  useEffect(() => {
    // trigger a submission when ready
    buttonRef.current.click();
  }, []);

  return (
    <Form method="POST" {...form.props}>
      {/* ... */}
      <button ref={buttonRef}>Submit</button>
    </Form>
  )
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@janhesters
Comment options

@fredericoo
Comment options

Answer selected by janhesters
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
Converted from issue

This discussion was converted from issue #248 on July 31, 2023 18:22.