You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unsure if this is an error in implementation or it's intentional (unsure why though), but using getZodConstraint with z.discriminatedUnion the fields are always set to as false on required although they are required by the schema.
Conform version
v1.1.4
Steps to Reproduce the Bug or Issue
consts=z.discriminatedUnion('a',[z.object({a: z.literal('1'),b: z.string(),// b should be requiredz: z.object({// z should be requiredu: z.string(),// z.u should be requiredy: z.string().optional(),}),}),z.object({a: z.literal('2'),c: z.string(),// c should be required}),]);
Output from getZodConstraint
{"a": {"required": true},"b": {"required": false// should be true},"z": {"required": false// should be true},"z.u": {"required": false// should be true},"z.y": {"required": false},"c": {"required": false// should be true}}
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.
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.
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
The text was updated successfully, but these errors were encountered: