点击一个编辑按钮,使用现有的数据填充表单。
在点击按钮的时候update state 为编辑状态,
在componentWillReceiveProps中调用setFieldsValue方法。大概1分钟左右以后表单填充完成,
然后我在点击任意Input,继续等待1分钟左右。
setFieldsValue
本质是调用外层 wrapper 的 setState
,间接调用 componentWillReceiveProps
,所以死循环了。
请用 mapPropsToFields
http://ant.design/components/form/#Form.create(options)
@benjycui 谢了
mapPropsToFields 把 props 转为对应的值,可用于把 Redux store 中的值读出
Function(props): Object{ fieldName: Object{ value } }
没看到 我要在mapPropsToFields怎么写
Hi, is there a way to translate this converstion?
@bnlambert What's your question
I wish to see how to set initial values with setFieldsValue
.
Also my datepicker calender is appearing in Chinese; how do I rectify it?
you can try moment.locale('en');
Do I requre moment from 'antd' or I need to download it separately?.
Please be a little bit more explicit. Thanks
On your website, there is this note for 'setFieldsValue'
please don't use it in componentWillReceiveProps, otherwise, it will cause an endless loop, more)
It links to this page for what i assume its an explanation. Could we get some sort of translation if possible ?
thx
@coljung try Google translator.
@bnlambert @coljung or if you're on chrome, right-click -> translate to English
I can understand that some issues were written in Chinese for convenient/faster communication between maintainers, but this one is referenced in the official documentation, it is "part of it" so it should be translated.
Alternative: the information written here should be included in the official documentation.
@benjycui IMO "try Google translator" is not a constructive comment and breaches some rules of conduct mentioned in CODE_OF_CONDUCT.md
- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members
To the 9 people who reacted with ":smile:": you are obviously bilingual, how long it would have been take to Google Translate the content, adjust the translation if needed thanks to your language skills and paste the content here instead ?
That being said:
setFieldsValue
in componentWillReceivedProps
causes a loop which eventually stops after 1 minute. Every field change causes a new "infinite" loop.setFieldsValue
leads to a this.setState
in the HOC, so it changes props and directly causes your componentWillReceiveProps
method to be called. That's why there is a loop. We should use mapPropsToFields
. mapPropsToFields
is used to read data from the store, how can I write in it ?这form是真难用,封装后使用成本太高
https://ant.design/components/form/#components-form-demo-global-state
mapPropsToFields 和 upload 冲突 上传会重置表单
Most helpful comment
这form是真难用,封装后使用成本太高