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.

Input doesn't get focused on setError with shouldFocusError

See original GitHub issue

Describe the bug Field doesn’t get focused with manual setError when useForm has option shouldFocusError: true

To Reproduce Steps to reproduce the behavior:

  1. Fill the last name and submit
  2. See error and focus are not set

Codesandbox link (Required) https://codesandbox.io/s/react-hook-form-useform-template-forked-wj5o6?file=/src/index.js

Expected behavior First name field is focused on error

Screenshots If applicable, add screenshots to help explain your problem. image

Desktop (please complete the following information):

  • OS: macOS Catalina 10.15.5
  • Browser: Chrome
  • Version: v84.0.4147.135

Additional context I would happy to take this issue if this behaviour is not expected. Thanks for awesome work

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
vadimshvetsovcommented, Aug 23, 2020

Thanks, didn’t thought about that. If user set error manually it totaly makes sense to control it with options

1reaction
bluebill1049commented, Aug 23, 2020

I don’t think it should by default,

  • what if multiple setError?
  • what if the user wants to omit that behavior for a particular error?
Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - How to focus when an error occurs in react-hook-form ...
You can use setFocus from RHF. First, detect when the errors object changes and then find the first field which has the object...
Read more >
useForm - setError - React Hook Form
Should focus the input during setting an error. This only works when the input's reference is registered, it will not work for custom...
Read more >
Form validation with react-hook-form - DEV Community ‍ ‍
If I submit the form with an empty password, I will not get any error message that indicate I forgot to input my...
Read more >
react-hook-form useForm TypeScript Examples
export function Dashboard() { const { errors, setError, register, formState, ... setError } = useForm(); const onSubmit = async (data) => { //...
Read more >
Create powerful and flexible forms with React Hook Form
React Form Hook is a React library that is used to make performant, ... const { setError, errors } = useForm(); <input name="username" ......
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