Replies: 2 comments 5 replies
-
I think you can use |
Beta Was this translation helpful? Give feedback.
0 replies
-
that sounds promising! fwiw neither of these work for me. I get a error:
const baseEditSchema = z.object({
ghgScope: z.preprocess((v) => Number(v), z.number()),
ghgScope3Category: z.number().nullish(),
minimumFidelity: z.string(), const baseEditSchema = z.object({
ghgScope: z.number().transform((v) => v),
ghgScope3Category: z.number().nullish(),
minimumFidelity: z.string(), |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What's the recommended approach for data transforms? For example, I have a
z.number()
field and my component is just a text editor (say with masking to add a$
or something), my current approach is to stringify / format the number on the way to the input and then parse it with a separate zod schema on the way out to turn it back into a number (z.string().regex(/^\d+$/).optional().transform(Number);
). Is this the recommended approach? Just handle it one off in each mapped component? I'd love to be able to define two way transforms in the schema but not sure if that would be possible with zod.. Just thought I'd ask in here for thoughts.Thanks for all your work on this great library!
Beta Was this translation helpful? Give feedback.
All reactions