-
|
Is it possible to set required_string after the schema has been created? so instead of this: I would like to do something like this: |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
|
Hi @gruni1992! I'm Dosu and I’m helping the zod team. Zod doesn't support updating the required field error message (like Schema-level error messages always take precedence, so if you want a different required message, you'll need to recreate the schema with the new message. Zod schemas are intentionally immutable after creation, and this is by design. More on error precedence and customization here: error customization. If you have a specific use case or need more tailored advice, let me know your Zod version. If this answers your question, feel free to close the issue! To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
|
You can't specifically set the const mySchema = z.object({someProperty: z.string()})
const mySchemaWithCustomRequiredMessage = mySchema.refine((val) => val === "", {
error: "this field is required"
}); |
Beta Was this translation helpful? Give feedback.
-
|
I just found a solution that works for me: |
Beta Was this translation helpful? Give feedback.
I just found a solution that works for me: