Open dkAndFed opened 4 months ago
@dkAndFed I think you need a z.string().min(1)
as outlined in the zod docs
It was intentional to keep only common properties as required. As it will make the form impossible to submit before JS loaded and it is too complex to update the constraint based on the current value.
@edmundhung Thanks for the explanation.
I suppose when using getZodConstraint
directly with useForm
, as intended, it makes sense what you are saying. My use however is without @conform-to/react
as I am relying on a different form library and I only need to know which fields are required.
I suppose I could write my own function to parse the schema and infer which fields are required.
Describe the bug and the expected behavior
Unsure if this is an error in implementation or it's intentional (unsure why though), but using
getZodConstraint
withz.discriminatedUnion
the fields are always set to asfalse
on required although they are required by the schema.Conform version
v1.1.4
Steps to Reproduce the Bug or Issue
Output from
getZodConstraint
What browsers are you seeing the problem on?
No response
Screenshots or Videos
No response
Additional context
The behavior seems to be caused by the following line of code; removing it resolves the issue and produces expected required values.
https://github.com/edmundhung/conform/blob/main/packages/conform-zod/constraint.ts#L90