Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form.List 中的某一项删除后,其他字段也被意外影响了 #5609

Open
awmleer opened this issue Aug 22, 2022 · 5 comments
Open

Comments

@awmleer
Copy link
Member

awmleer commented Aug 22, 2022

Version of antd-mobile

5.22.0

Operating system and its version

Others

Browser and its version

Chrome

Sandbox to reproduce

https://stackblitz.com/edit/react-ts-ufnhw9?file=App.tsx

What happened?

复现方法是:

  1. 打开上面的 demo
  2. 点添加按钮,添加三项内容,并分别输入一些值
  3. 删除第二项
  4. 发现此时第三项的值也异常了

预期行为:

点击删除之后,第三项的值保持不变,仅第二项被删除掉

额外一点补充:

把 Form 上的 preserve={false} 去掉就行为正常了
疑似 rc-field-form 的问题

Relevant log output

No response

@IronKinoko
Copy link
Collaborator

<Form.Item 
+ isListField
  name={[index, 'checkConfig']}
  label={`"bug"-${index}`}

加上这个属性后就正常了。需要组件内部处理下

@awmleer
Copy link
Member Author

awmleer commented Aug 27, 2022

噢原来是这样~还有个内部 API

@IronKinoko 你有兴趣来提个 PR 嘛

@IronKinoko
Copy link
Collaborator

我看了 antdprocomponent 也没处理这个,只有 preserve={false} 受影响

@wine-fall
Copy link
Contributor

这个感觉不好改😳

要么就在 readme 里头加个提醒?

要么就基于From.Item 再封一层 Form.ArrayItem,默认加上 isListField。然后还得在 readme 里提醒用户在使用 Form.Array 的时候得使用这个 Form.ArrayItem

再要么就得大改 Form.Array 了?目前这个是直接调用 props.children() 的,而它的类型是 (fields: FormArrayField[], operation: FormArrayOperation) => ReactElement[],这个组件层面没法控制。

@damonyoungcc damonyoungcc unpinned this issue Nov 4, 2022
@RoyRao2333
Copy link

RoyRao2333 commented Sep 3, 2024

antd-4同样遇到了这个问题,但是似乎不推荐传isListField:

image

只有先把preserve={false}干掉了,不知道这个在antd-5中修复没有,但是目前项目原因无法完全使用V5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants