Validator schema as subset of default values
So I've a form where I temporarily keep some values, which are set in my default values but on submit, they are discarded by the zod schema.
For example:
In current implementation, it'll give error because schema has user missing. I need user object in my form for displaying purposes so I can't just cast defaultValues to schema type.
3 Replies
flat-fuchsia•4mo ago
if it's only for displaying purposes, why is it in the defaultValues? can they be changed? do they need validation?
inc-lavenderOP•4mo ago
Yes, such objects can be changed. Example if a stock item has a product in it, I only wanna send productId when saving. But I may need to update UI based on selected product.
Eg my Product Autocomplete onChange could look like this:-
And no,
product
is not validated in this case. Its just stored temporarily for displaying info.
When form is submitted, zod will just remove it from the payload sent to the server.flat-fuchsia•4mo ago
sounds like a use case for Form.Subscribe
subscribe to productId and display related information