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
And hence the .optional() does not work as the value is not null.
I think the best workaround would be to seriously consider something like z.file().mime(...).formOptional() which would try if the file has empty values.
Note that I tried the following schema for a text field, but it does not generate any errors.properties that I could reuse in my Svelte views.
Hi,
I'm a huge Svelte and Zod fan, and I think my only problem with Zod is that it doesn't manage well formData empty values.
For example, here are empty inputs formData values :
file
File { size: 0, type: 'application/octet-stream', name: '', lastModified: ... }
text
""
And hence the
.optional()
does not work as the value is notnull
.I think the best workaround would be to seriously consider something like
z.file().mime(...).formOptional()
which would try if the file has empty values.Note that I tried the following schema for a text field, but it does not generate any errors.properties that I could reuse in my Svelte views.
z.url().or(z.string().length(0, { error: 'Invalid URL' }).nullish())
Here is another example with the file input :
and the
z.file().optional()
does not seem to work, because it throws the error :The text was updated successfully, but these errors were encountered: