admin管理员组文章数量:1332881
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.
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.
-
Two reasons 1) you're using a custom
TextField
stateless ponent:ponent={TextField}
. You cannot assign a ref to a stateless ponent. ConvertTextField
to a class ponent. 2) You need to add thewithRef
prop to your reduxFormField
ponent – Chase DeAnda Commented Jul 10, 2018 at 14:14
2 Answers
Reset to default 3- You must assign the ref to the input element instead of the Field ponent
- Add an callback to set in your parent ponent the reference of subponent input
- Use the reference to focus the input when pressing the edit button:
https://codesandbox.io/s/rlx390xn6m
just HTML's autofocus
is much better:
https://davidwalsh.name/autofocus
- in react use with camelcase:
autoFocus
本文标签: javascriptEnable reduxform and set focus to fieldStack Overflow
版权声明:本文标题:javascript - Enable redux-form and set focus to field - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742304813a2449705.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论