Validation does not trigger until submit is invoked
See original GitHub issueDescribe the bug Automatic validation starts to trigger only after submit is invoked.
Typing text to input fields does not update the errors object or formState.isValid property until I have tried to submit.
After clicking and trying to invoke submit all changes to input values are validated in real time. Seems like something is blocking the execution until submit.
I have used the exact Getting started example
To Reproduce Steps to reproduce the behavior:
npx create-react-app form-test
npm install react-hook-form
- Modify App.js
import React from 'react';
import './App.css';
import { useForm } from "react-hook-form";
function App() {
const { register, handleSubmit, watch, errors, formState } = useForm();
const onSubmit = data => console.log('submit', data);
console.log('exampleRequired', watch("exampleRequired")); // watch input value by passing the name of it
console.log('formValid', formState.isValid);
console.log('errors', errors);
return (
<div className="App">
<form onSubmit={handleSubmit(onSubmit)}>
<input name="example" defaultValue="test" ref={register} />
<input name="exampleRequired" ref={register({ required: true })} />
{errors.exampleRequired && <span>This field is required</span>}
<input type="submit" />
</form>
</div>
);
}
export default App;
npm start
Desktop (please complete the following information):
- OS: macOS 10.15.4
- Browser [Chrome 83.0.4103.61]
Console output for typing ‘a’ into the text input and clicking submit. Causes awful many renders for some reason.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Angular Reactive Forms: trigger validation on submit
In this article we will learn different approaches of validating all form fields when user clicks on submit button for Angular Reactive ...
Read more >Trigger standard HTML5 validation (form) without using submit ...
Short answer, no, there's no way to 'trigger' the default functionality of the html5 bubble inline before submission of the form, you can...
Read more >requestSubmit offers a way to validate a form before submit
The fairly new requestSubmit method on the HTML form element allows developers to trigger form validations and submit.
Read more >useForm | React Hook Form - Simple React forms validation
Validation will trigger on the submit event and inputs will attach onChange event listeners to re-validate them. onBlur, string, Validation will trigger on...
Read more >Handling Forms - VeeValidate
So if you were to add a submit handler on the <Form /> component, vee-validate will automatically pass the form values to your...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
all good! a simple one 👍
Duh, solved. Thank you.
I got confused with the