question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getFieldDecorator with nested field format is not allowing arrays of objects to setFieldsValue

See original GitHub issue

Version

2.9.1

Environment

Mac OS, chrome, react ^15.4.2

Reproduction link

http://codepen.io/ffab00/pen/wdGrVQ

Steps to reproduce

When adding a getFieldDecorator for a field inside array of objects it prevents setFieldsValue from saving. This makes it hard to create repeatable sections.

Open codepen link, Click add button multiple times, it will not add more section, Remove line 36 {form.getFieldDecorator('pumps[' + index + '].make', { })(<Input />)}
And sections will be added

What is expected?

Expected to be able to add multiple sections of fields in array field.

What is actually happening?

New objects are not pushed to array by setFieldsValue when getFieldDecorator for nested field is present in render


I was trying to create a form with repeatable groups of fields (array of objects). Would appreciate working examples. Followed this example initially https://github.com/ant-design/ant-design/blob/master/components/form/demo/dynamic-form-item.md but extended it to allow multiple fields in each array/object.

May be related to https://github.com/react-component/form/pull/48

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
zhongkaicommented, Jun 13, 2017

这个问题解决了么?或者有什么办法,能让一个数组源的项目能够展示出来,并且可以动态的增删呢? 急~

1reaction
dzoneocommented, Aug 23, 2017

I got a way to solve this:

const columns = this.props.form.getFieldValue('columns');
const newColumns = columns.map((item, idx) => {
  if(idx === index) {
    return Object.assign({}, item, {name: value});
  }

  return item;
});

this.props.form.setFieldsValue({
  columns: newColumns,
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - getFieldDecorator with nested field format is not ...
getFieldDecorator with nested field format is not allowing arrays of objects to setFieldsValue.
Read more >
How to fix it Cannot use `setFieldsValue` - Stack Overflow
I faced the same issue with react hooks. Following solution works for me. props.form.getFieldDecorator('Amount', { initialValue: 'My Value' }).
Read more >
Nested Antdesign Forms With Getfielddecorator In React
Antdesign: getFieldDecorator with nested field format is not allowing arrays of objects to setFieldsValue Version. 2.9. Environment. Mac OS. Form nested and ...
Read more >
Form - Ant Design
High performance Form component with data scope management. Including data collection, verification, and styles.
Read more >
Form - Ant Design - GitHub Pages
A form consists of one or more form fields whose type includes input, textarea, checkbox, radio, select, tag, and more. A form field...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found