react-hook-form validate onChange #9252
-
Below is my form using import React from 'react';
import { useForm } from 'react-hook-form';
export default function App() {
const { register, handleSubmit, formState: { errors } } = useForm();
const onSubmit = data => console.log(data);
console.log(errors);
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input type="text" placeholder="username" {...register("username", {required: true, maxLength: 80})} />
<input type="undefined" placeholder="Email" {...register} />
<input type="submit" />
</form>
);
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
just add onchange
not sure if this work, I just made another question, hope this help. |
Beta Was this translation helpful? Give feedback.
-
useForm({
mode: "onChange"
}) does exactly that. Please, refer to RHF docs to learn more |
Beta Was this translation helpful? Give feedback.
-
Will this still work when passing in a resolver?
The only validation occurs on submit, even though I've specified onChange. |
Beta Was this translation helpful? Give feedback.
does exactly that. Please, refer to RHF docs to learn more