ant-design 在formList中使用shouldUpdate

xfb7svmp  于 4个月前  发布在  其他
关注(0)|答案(4)|浏览(65)

Steps to reproduce

增加一个list项,为Gender添加一个值,再为other,添加一个值,在改变Gender为other值,再为Customize Gender,添加一个值

What is expected?

输出的表单值只有gender和Customize Gender

What is actually happening?

输出的表单值只有gender和Customize Gender,还有other值
| Environment | Info |
| ------------ | ------------ |
| antd | 4.20.4 |
| React | ^16.14.0 |
| System | 无 |
| Browser | 无 |

在单纯的表单中使用,是正常的,只有在formList中使用就会发生这种情况

cnwbcb6i

cnwbcb6i1#

遇到同样问题,貌似还没修复

vshtjzan

vshtjzan2#

In my case, when I added a new item, or remove (any actions); shouldUpdate still runs, but these values ( preValue , and currentValue is the same) -> So, I try to change the approach, which allows me to get onChange event in the list ( add , remove ) and customize it to an input box.

You can try this solution:
Current state:

<Form.List name="list0">{...}</Form.List>

Change to:

<Form.List></Form.List>
<Form.Item name="rule0"><CustomComponent /></Form.Item>

When you handle add , or remove an item from the list, run it with form.setFieldsValue function to set a new value for list0 .

Yay, it works for me!

snvhrwxg

snvhrwxg3#

I also had the same problem

1u4esq0p

1u4esq0p4#

@afc163@MadCcc Is this issue still of concern?

相关问题