Array of objects serialization not working on Actions #167
Unanswered
VigneshVaidyanathan
asked this question in
Q&A
Replies: 1 comment
-
Hi! Would you mind providing a specific example in the form of a code sandbox? The I wouldn't expect |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Need help with Array of objects using Remix Validated Form.
I am trying to validate an array of objects using remix-validated-form and it works well during validation when I set the name property in the form as
questions[${index}].placeholder
but when I set it asquestions[${index}][placeholder]
it doesnt validate it properly.When I use the format
questions[${index}].placeholder
, Remix does not allow to properly serialize it. (Or I might be missing an obvious thing to read using Remix).So instead if I use
zod-form-data
to properly serialize it, I have to redo all my schemas that I had for client validation, in server usingzod-form-data
.I also have multiple action types happening in the same action function likecreate
,update
,create_form
etc, which have different payloads and different schema. So redoing all those again is making it difficult to maintain.I see the
zod-form-data
is a sugar on top of zod and uses prepreocess and validation logic to parse data into schema types, is there a way to reuse existing zod schema there.questions[${index}][placeholder]
for inputs and arrays. For nested arrays likequestions[${index}][placeholder][0][name]
zod-form-data
to parse and get the object exactly like the existing zod schema.Beta Was this translation helpful? Give feedback.
All reactions