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

What is the correct way to update a property in touched store that is array of objects? #188

Open
arteforme opened this issue Mar 24, 2023 · 0 comments

Comments

@arteforme
Copy link

I have a use case where I need to allow a user to enter box dimension info for one or more boxes. The form initially begins with fields for a single box, but I allow the user to add additional box info as needed by clicking on a button that will dynamically add additional form fields. To account for that scenario, I'm calling `updateValidatedField. Below is my schema

let boxSchema = object({
    height: number().required(),
  });

let shippingSchema = object({
    boxes: array(boxSchema).min(1).required(),
});

The initial state of the touched store is {"boxes": [{}]}. After calling updateValidateField, the shape of touched is {"boxes":true} which is not what I'm expecting. After looking through source, it looks like the root cause is on line 76

If instead, I call updateField, touched is not updated and so I'd need to call updateTouched as well. For example:

updateField("boxes", shippingInfo.boxes);
updateTouched("boxes", [...$touched.boxes, {}]);

Which produces the result I'm expecting {"boxes":[{},{}]}. Is this the route I should be taking?

Please see this codesandbox.io for example

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

No branches or pull requests

1 participant