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.

Form.Item dependencies don't work when a partial resetFields is triggered

See original GitHub issue
  • 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.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
dnbastoscommented, Dec 16, 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

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 })
0reactions
afc163commented, Nov 29, 2021

Similar issue #33068

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to disable a field in Ant Design React Form?
I am using React with Ant Design and I want to disable one Form.Item username field. Please see my ...
Read more >
Form - Ant Design
Does not work when multiple Item with same name setting the initialValue. Why does onFieldsChange trigger three times on change when field sets...
Read more >
Form | ArcoDesign
A form with data collection, verification and submission functions, including checkboxes, radio buttons, input boxes, drop-down selection boxes and other ...
Read more >
useFieldArray - Simple React forms validation
Custom hook for working with Field Arrays (dynamic form). The motivation is to provide better user ... Important: update data is required and...
Read more >
React Hook Form - Reset form with default values and clear ...
Reset and form default values. Calling the reset function with an object (e.g. reset({ firstName: 'Bob' }) ) will also update the defaultValues ......
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