Null fields not working as expected
Hi all,
I am using Drizzle ORM with Zod validation for useForm, and I am running into issues with fields that are allowed to be undefined / null, but I get Zod errors stating that the value of the optional fields (when left empty) are
invalid_type
and in required.
I was able to fix this by refining the field as follows:
This allows the city
field to be left blank, but by default, even though i didn't specify notNull()
on that field, Zod would error out saying that the field is required.
I am using Turso DB, so this is my schema:
Notice for all fields by the id
, organizationId
, and name
, they are optional; however, Zod treats them as ZodNullable
but they should in fact be treated as ZodOptional<ZodNullable<ZodString>>
to allow my fields to be empty (as is the intended affect).1 Reply
Hi ,
i'm having the same problem did you found a solution