IdoPesok/zsa

Usage with Conform library (raw FormData input)

Kamahl19 opened this issue · 4 comments

Hey, thanks for the great library. I would like to use it together with the Conform library which is a great alternative to react-hook-form. However Conform library does its own transformation of FormData to json and schema validation (https://conform.guide/api/zod/parseWithZod).

I suppose I would need something like .input(undefined, { type: 'raw' }) which would simply pass the unprocessed input to the handler. There I would use the FormData and pass it to the Conform library.

I would appreciate this solution as well.

I'm curious if .input(z.custom<FormData>()) would work instead of raw?

@IdoPesok That's a good point but it's not enough. Due to this line

...formDataToJson(data, inputSchema),
the formData is first converted to json. That's why I suggested a raw type to bypass that.

If you see a value in this, I would be happy to make a PR, whatever we agree on. I guess you might have a better idea to solve this, maybe something more idiomatic than raw.

@IdoPesok I have come up with a simple solution #191 , please let me know what are your thoughts. Thanks!