简体   繁体   English

禁用浏览器滚动到错误输入

[英]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顺便说一句,我使用 react-hook-form

When you create your form with the useForm hook you just need to set the shouldFocusError to false当您使用 useForm 钩子创建表单时,您只需将shouldFocusError设置为 false

eg例如

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

ref: https://react-hook-form.com/api/useform参考: 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.是的,文档说 { shouldFocusError: false } 会完成这项工作,但在我的情况下它也不起作用,我正在使用带有模式的 yup 解析器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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