question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validation does not trigger until submit is invoked

See original GitHub issue

Describe 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:

  1. npx create-react-app form-test
  2. npm install react-hook-form
  3. 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;

  1. 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. image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bluebill1049commented, Jun 5, 2020

mode : https://react-hook-form.com/api

Duh, solved. Thank you.

I got confused with the

reValidateMode: 'onChange'

all good! a simple one 👍

1reaction
Spaidericommented, Jun 5, 2020

mode : https://react-hook-form.com/api

Duh, solved. Thank you.

I got confused with the

reValidateMode: 'onChange'
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found