admin管理员组文章数量:1434909
React js with Zod validation superRefine not updated realtime with values changes
for this code every thing is fine but I want when the user start with the end date and then the error show "select start date first" after that return back to start date and select start date error of "select start date first" is still shown why is that and how to solve it
const formSchema = z
.object({
game: z.string().min(1, { message: "you must select at least one game" }),
tournamentName: z
.string()
.min(2, "Tournament Name must be at least 2 characters."),
platform: z.enum(["mobile", "pc", "xbox"]),
description: z.string(),
rules: z.string(),
coverImage: z.any(),
profileImage: z.any(),
startDate: z
.date()
.refine(
(date) => date instanceof Date && !isNaN(date) && date > new Date(),
{
message: "Start Date must be a valid date and in the future.",
}
),
endDate: z.date().refine((date) => date instanceof Date && !isNaN(date), {
message: "End Date is required.",
}),
})
.superRefine((data, ctx) => {
const { startDate, endDate } = data;
console.log(data);
if (!startDate && endDate) {
ctx.addIssue({
path: ["endDate"],
message: "select start date first",
});
}
if (startDate > endDate) {
ctx.addIssue({
path: ["endDate"],
message: "End Date must be after Start Date.",
});
}
});
React js with Zod validation superRefine not updated realtime with values changes how can I get real time updating that when I update end date without start date set --> error "you must select start date" and if return to start date the error must not shown all things real time
版权声明:本文标题:javascript - React js with Zod validation superRefine not updated realtime with values changes - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745634917a2667497.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论