[英]React-select & creatable select with reatc-hook-form focus on validation error
I am using create select components inside a react-hook-form.我在 react-hook-form 中使用 create select 组件。 I have tried the react-select and creatable-react-select both and the behaviour I experience in context of this issue is the same.
我已经尝试过 react-select 和 creatable-react-select 两者,我在这个问题的上下文中遇到的行为是相同的。
Using latest react-hook-form (7.6.1), I can't set the field to be focussed when there's an error bound to the field.使用最新的 react-hook-form (7.6.1),当字段绑定错误时,我无法将字段设置为焦点。 CODE SANDBOX EXAMPLE FOR THIS
为此编写沙箱示例
When I use an older version of react-hook-form, I can get this behaviour to work as expected.当我使用旧版本的 react-hook-form 时,我可以让这种行为按预期工作。 CODE SANDBOX EXAMPLE FOR THIS
为此编写沙箱示例
As i want this behaviour to work in the latest react-hook-form, any suggestions on what is the problem in the first example?因为我希望这种行为在最新的 react-hook-form 中起作用,所以对第一个示例中的问题有什么建议?
using controller for react-select component but did not use prop "field" from "render" method of Controller, therefore, the ref element is not set in order to help react-hook-form to set focus.使用 controller 作为 react-select 组件,但没有使用 Controller 的“render”方法中的 prop“field”,因此,未设置 ref 元素以帮助 react-hook-form 设置焦点。
Working sample: code sandbox工作示例: 代码沙箱
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.