首页 > 解决方案 > 禁用浏览器滚动到错误输入

问题描述

当我提交表单并且表单有错误时,例如空的必需输入,浏览器会向上滚动到该输入。我不想要那个。我有自定义滚动到错误的输入和浏览器滚动干扰我的。如何禁用此功能?

顺便说一句,我使用 react-hook-form

标签: javascripthtmlreactjs

解决方案


当您使用 useForm 钩子创建表单时,您只需将其设置shouldFocusError为 false

例如

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

参考:https ://react-hook-form.com/api/useform


推荐阅读