form icon indicating copy to clipboard operation
form copied to clipboard

Remove Field without using component's Mount/Unmount

Open jwmann opened this issue 6 years ago • 1 comments

I have dynamic fields set up as per the Ant Design example https://ant.design/components/form/#components-form-demo-dynamic-form-item

However, I need to keep the form object to show another step of the submission process. Luckily, getFieldDecorator() has a nice option called preserve: true that does exactly that.

Unfortunately though, this doesn't work nicely with dynamic fields. When the user removes a field, the field stays in the form object, which is expected as the field is set to preserve.

I'd need a way to manually remove this field from the form object programmatically without relying on the mount/unmount of the component.

Reference to this issue from a while back #160


Edit Ant Design Form - Remove preserved Field issue

If you use my above example, you can see the issue I'm having/

Reproduce with this:

  1. Add 3 fields
  2. Input a value of 1, 2, 3 for each corresponding input box. So we can tell the difference.
  3. Remove the 2nd field using the minus button.
  4. Click "Next". -- The Form should now "Unmount" but the Form object will be preserved.
  5. Click "Submit" and view the console.log
  6. Console.log shows all names have been preserved

The dynamic example relies on the the field to be unmounted in order to delete it from the form object. However, I need these fields in order to submit them later on Page 2.

I need to use this in a much more complex way in my actual app but this is a simplification of the problem that I'm trying to solve.

Anybody have any ideas on how to solve this?

jwmann avatar Mar 29 '19 23:03 jwmann

the same problem I meet

WellerQu avatar May 24 '19 11:05 WellerQu