【问题标题】:Disable browser scroll to errored input禁用浏览器滚动到错误输入
【发布时间】:2021-04-22 07:49:10
【问题描述】:

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

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

【问题讨论】:

    标签: javascript html reactjs


    【解决方案1】:

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

    例如

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

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

    【讨论】:

      猜你喜欢
      • 2018-06-20
      • 1970-01-01
      • 2021-02-25
      • 1970-01-01
      • 2014-06-27
      • 1970-01-01
      • 2012-03-14
      • 2011-02-02
      • 2010-09-19
      相关资源
      最近更新 更多