Questions tagged [zod]
A JavaScript/TypeScript library for TypeScript-first schema validation with static type inference.
623
questions
0
votes
0
answers
14
views
Adding objects within a specific Array type in React TypeScript
I'm writting the shchema of my web app by Zod and I'm creatig different message errors to input objects. A minimum length for one and a user verified in the other case.
The minimum length condition ...
0
votes
0
answers
41
views
Using zod form validation with radio button group that has no default checked value on first render
I have a simple form that I am using zod to validate. For simplicity let's say the form has exactly one user field for specifying a selection:
const FormSchema = z.object({
options: z.enum(["...
0
votes
0
answers
12
views
Error in date typing using the z.input and z.output method
I have a service registration modal in which the user can initially enter a date in Date type, but it is sent to the API as a string in the future.
I've used the z.input and z.output methods to deal ...
0
votes
0
answers
91
views
Shadcn combobox with zod error: TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
I have this select from shadcn and I am trying to use it with zod. Upon clicking on the select, it would show these errors:
TypeError: undefined is not iterable (cannot read property
Symbol(Symbol....
0
votes
1
answer
24
views
node.js health api request test fails by zod validation?
I have a Node.js Express application that I'm trying to test using vitest and supertest. However, I'm encountering issues with missing environment variables. Here’s my setup:
Environment Configuration ...
0
votes
1
answer
93
views
On svelte Superform, how to display error message without using +page.server.ts
I am using shadcn-svelte form for my Svelte application. Currently, I am trying to validate my form data client-side using Zod and display the error messages below the input fields. However, I'm not ...
0
votes
1
answer
39
views
Zod > video file duration check (Javascript mastery required)
I'm trying to use Zod and validate video file input duration. The issue is that to load metadata, there needs to be async / await and this is where I've reach my Javascript mastery limit. This is what ...
0
votes
1
answer
74
views
NextJS, Zod and React Hook Form - Controlled and Uncontrolled Components
I'm using NextJS 14, Zod and ShadCN UI which uses React-Hook-Form.
I'm in a scenario where I'm creating a form that can be used for both 'create' and 'update'. I pass values into the form and set ...
0
votes
1
answer
51
views
Why is my conditional validation not working using zod and react-hook-form?
Good Day! I'm having a little trouble after refactoring my code, I created a conditional field wherein if the user selected Yes there will an additional field below wherein the user must answer it. ...
0
votes
1
answer
37
views
How can I disable next button if the user didn't complete the first step?
so I've created a multi-step form using shadcn , react-hook form and zod. I've created 3 types of zod schema and joined them using z.union from zod. The problem I'm encountering right now is I can ...
0
votes
0
answers
20
views
React hook form + zod: How to skip check on empty field when "onBlur"?
I have a signin form, with email & password fields, and the email field is auto-focused.
There's also a "forgot password" link that redirect user to another form.
I'm using zod and "...
-1
votes
0
answers
22
views
How to validate a field that depends on another field of the same schema in Zod
I have a situation where I need to validate a field based on a value of the same schema.
Here is a code snippet what should make my intention clear:
import { z } from "zod";
const ...
1
vote
1
answer
60
views
react-hook-form field array custom refine error state won't update
My fieldValues are as follows:
export const schema = z.object({
urls: z
.array(
z.object({
path: z.string().url(),
main: z.boolean(),
id: z.string(),
})
...
0
votes
1
answer
25
views
Enforce Base Schema Type in Generic Constraint
Is it possible for Zod to enforce that a passed schema's type is constrained to a base schema? I suspect I might be way off base here, but hopefully it is clear what I'm trying to achieve in the ...
0
votes
1
answer
53
views
Is it possible to preprocess discriminator in zod discriminated union?
I need to coerce string formatted numbers to number before using a value in z.discriminatedUnion. Is this possible? Here is a simplified code snippet:
import { z } from "zod";
const ...