form
form copied to clipboard
Remove Field without using component's Mount/Unmount
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
If you use my above example, you can see the issue I'm having/
Reproduce with this:
- Add 3 fields
- Input a value of 1, 2, 3 for each corresponding input box. So we can tell the difference.
- Remove the 2nd field using the minus button.
- Click "Next". -- The Form should now "Unmount" but the Form object will be preserved.
- Click "Submit" and view the console.log
- 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?
the same problem I meet