Ant-design: Form setFieldsValue 方法参数是什么,我传入一个对象,在componentWillReceiveProps中执行死机了

Created on 9 Sep 2016  ·  16Comments  ·  Source: ant-design/ant-design

  • antd 版本: 1.11.0
  • 操作系统及其版本:MAC 10.11.6 内存16G CPU i7
  • 浏览器及其版本: CHROME

点击一个编辑按钮,使用现有的数据填充表单。

在点击按钮的时候update state 为编辑状态,
在componentWillReceiveProps中调用setFieldsValue方法。大概1分钟左右以后表单填充完成,
然后我在点击任意Input,继续等待1分钟左右。

Most helpful comment

这form是真难用,封装后使用成本太高

All 16 comments

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');

https://ant.design/components/date-picker/ doc

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:

  1. the OP describes the problem: Calling setFieldsValue in componentWillReceivedProps causes a loop which eventually stops after 1 minute. Every field change causes a new "infinite" loop.
  2. the maintainer answered that 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.
  3. the OP thanks the maintainer
  4. An other (unanswered) question is asked. mapPropsToFields is used to read data from the store, how can I write in it ?

这form是真难用,封装后使用成本太高

mapPropsToFields 和 upload 冲突 上传会重置表单

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PeteAndersen picture PeteAndersen  ·  3Comments

Orbyt picture Orbyt  ·  3Comments

zhangchen2397 picture zhangchen2397  ·  3Comments

mineralres picture mineralres  ·  3Comments

longhuasishen picture longhuasishen  ·  3Comments