How to reset Array Fields #118
-
In my project, if an array field with nested fields has a default value; when the form resets, it resets the array field as I would expect. The problem is that after the reset the form is still marked as dirty, even though visually all fields have returned to their default state. Upon further inspection on the form state, the only field marked as dirty in list of dirty fields is the array field AND it seems that the form still has the added fields that were added to the array. Is this a bug or am I suppose to be unregistering the fields that were removed from the form while it was resetting in some way? Any directions would be greatly appreciated. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
On first look this seems to be an issue with the library, I will check it out and get back to you, thank you for noticing 👍 |
Beta Was this translation helpful? Give feedback.
-
So two issues played a role here. First, I calculated the default values for nested fields wrong. I created undefined default values for nested fields. Now, I just ignore fields for the default values that have none defined. Secondly, I kept fields after they were unmounted; now, they always get removed once they are unmounted, and only the value is kept (unless you specify the A new version will be deployed later today. |
Beta Was this translation helpful? Give feedback.
So two issues played a role here.
First, I calculated the default values for nested fields wrong. I created undefined default values for nested fields. Now, I just ignore fields for the default values that have none defined.
Secondly, I kept fields after they were unmounted; now, they always get removed once they are unmounted, and only the value is kept (unless you specify the
removeValueOnUnmount
option on the field).A new version will be deployed later today.
I hope this helps.