How to manually validate the whole form? #350
Replies: 3 comments 2 replies
-
|
Conform will validate the entire form when you click on any submit buttons. If you don't want it to be submitted, you can set a custom name and value to the button and call export function Example() {
const [form, fields] = useForm({
onSubmit(event, { formData }) {
// The name "intent" and value "validate" depends on what you set on the button
if (formData.get('intent') === 'validate') {
event.preventDefault(); // This will stop it from being submitted
}
}
})
return (
<form>
{/* .... */}
<button name="intent" value="validate">Validate form</button>
</form>
);
} |
Beta Was this translation helpful? Give feedback.
-
|
How can this be done in code, I have tried to change an intent input with a validate value before trying to submit but if I use the form.ref.current.submit(), the onSubmit isn't fired from useForm()? |
Beta Was this translation helpful? Give feedback.
-
|
The idea here is to do validation via code, I am using Remix.js useFetcher to POST the form. an Example of using a fetcher would be good. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there,
I have a requirement to validate the entire form from a button, and have the UI update to show the form errors, how can I do this?
Regards
Jason Coley
Beta Was this translation helpful? Give feedback.
All reactions