Replies: 2 comments
-
Thanks for sharing your approach here! I think we have similar ideas on this. What you missed is the discriminatedUnion API from zod. You can also find an example I shared here. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply! I think using Still, I did consider giving an intent value to the submitting button, I just thought it'd be nicer to have the Not really sure there though, what is the point of setting conform.INTENT if not to separate different form intents? |
Beta Was this translation helpful? Give feedback.
-
I'm not sure if there is already a way of achieving this withing the library but I will share my approach here:
Usecase:
Imagine a single page shows a 'create post' Form and multiple posts, each of them being with two diferent interactions: like and report.
I think the standard approach right now is something like this:
what I would like better is the schema to be a discriminated union with the different intents and their respective fields.
An api like this:
I think this approach is better because it keeps the intent and the field together. Making it impossible to confuse the relation between the different fields and their intents.
My implementation of the parseWithIntent function looks like this and seems to be inferring the types correctly:
However, it does not correctly implement the "config" parameter which means you can't parse asyncronously and other options that the config parameter would allow you to tweak.
Beta Was this translation helpful? Give feedback.
All reactions