简体   繁体   中英

Disable browser scroll to errored input

When I submit form and the form has errors, like empty required input, browser scrolls up to that input. I dont want that. I have custom scroll to errored inputs and browsers scroll interfere with mine. How to disable this?

btw I use react-hook-form

When you create your form with the useForm hook you just need to set the shouldFocusError to false

eg

const { register } = useForm({
  // ... other settings
  shouldFocusError: false,
})

ref: https://react-hook-form.com/api/useform

Yeah the documentation says the { shouldFocusError: false }, will do the work but In my case it also not working and I am using yup resolver with schema.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM