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.Item dependencies don't work when a partial resetFields is triggered #31271

Open
1 task done
dnbastos opened this issue Jul 5, 2021 · 7 comments
Open
1 task done
Labels

Comments

@dnbastos
Copy link

dnbastos commented Jul 5, 2021

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

  • Check hasName field to false.
  • Click in "reset hasName" button

What is expected?

The name field should be re-mount when the hasName value changes. The disabled state of name field should be synchronized with hasName form value.

What is actually happening?

When form.resetFields(["hasName"]) is called, the name field render is not updated.

Environment Info
antd 4.16.6
React 17.0.2
System macOS Big Sur
Browser Google Chrome 91.0.4472.114 (Official Build) (x86_64)

Note that with form.resetFields() without params or changing the hasName value by radio field, the re-mount works.

@dnbastos
Copy link
Author

dnbastos commented Jul 5, 2021

In addition, when we set the form value programmatically with form.setFieldsValue({hasName: true}) the field update also not work.
https://codesandbox.io/s/antd-reproduction-template-forked-ocfq4?file=/index.js

@haggen
Copy link

haggen commented Sep 20, 2021

Any news on this?

@github-actions github-actions bot removed the Inactive label Sep 20, 2021
@JackClown
Copy link

+1

@haggen
Copy link

haggen commented Nov 16, 2021

+1

@afc163
Copy link
Member

afc163 commented Nov 29, 2021

Similar issue #33068

@dnbastos
Copy link
Author

In addition, when we set the form value programmatically with form.setFieldsValue({hasName: true}) the field update also not work. https://codesandbox.io/s/antd-reproduction-template-forked-ocfq4?file=/index.js

This part of the issue has been fixed in the v4.17.0.

It still doesn't seem like the best solution, but it helps me because I can use setFieldsValue to change to the default value instead of resetFields.

- form.resetFields(["hasName"])
+ // Gotta use setFieldsValue instead of resetFields since resetFields
+ // fails to trigger a dependency update.
+ form.setFieldsValue({ hasName: true })

@hesetiema
Copy link

+1

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

No branches or pull requests

5 participants