启用 redux-form 并将焦点设置为字段

启用 redux-form 并将焦点设置为字段

问题描述:

默认情况下我禁用了表单字段,当用户单击按钮 Edit 时,它将启用该字段.我也想把重点放在这个领域,但我不知道怎么做.我已经为该字段创建了 ref 并在其上尝试了一些 focus() 函数,但它没有工作.您可以在 sandbox 上试用.

I've got disabled form field by default and when user clicks on button Edit, it will enable the field. I also want to set focus on the field, but I don't know how. I've created ref to the field and tried some focus() function on it, but it hasn't worked. You can try it here on sandbox.

  1. 您必须将 ref 分配给 input 元素而不是 Field 组件
  2. 添加回调函数,在父组件中设置子组件输入的引用
  3. 在按下编辑按钮时使用引用来聚焦输入:

https://codesandbox.io/s/rlx390xn6m