javascript - React-select & creatable select with reatc-hook-form 专注于验证错误
问题描述
我在 react-hook-form 中使用创建选择组件。我已经尝试过 react-select 和 creatable-react-select 两者,我在这个问题的上下文中遇到的行为是相同的。
使用最新的 react-hook-form (7.6.1),当字段绑定错误时,我无法将字段设置为焦点。 为此编写沙箱示例
当我使用旧版本的 react-hook-form 时,我可以让这种行为按预期工作。 为此编写沙箱示例
因为我希望这种行为在最新的 react-hook-form 中起作用,所以对第一个示例中的问题有什么建议?
解决方案
对 react-select 组件使用控制器,但没有使用 Controller 的“render”方法中的 prop“field”,因此,未设置 ref 元素以帮助 react-hook-form 设置焦点。
工作示例:代码沙箱
推荐阅读
- java - 如何使用正则表达式从字符串中捕获所有实例
- javascript - 如何根据另一个组件的状态更改 CSS 属性
- node.js - 注册节点/快递的身份验证时缺少用户名错误
- arrays - 为什么嵌套数组在python中复制其元素?
- webpack - 无需重建整个静态网站的动态内容和组件?
- unix - HP-UX 上的备份命令失败
- apache - Codeigniter 删除 index.php 在本地工作,但不适用于 aws ELB
- sparql - 如何使用 Python 确定两个 SPARQL 查询是否相同?
- c# - C# WPF Behavior 类,由于 Windows 缩放更改,卸载 UIElement 后 AssociatedObject 为 null
- python - 仅当所有任务完成后才保存任务结果