is there a reason why initialErrors in useForm requires all fields? #5107
Unanswered
binaryartifex
asked this question in
Q&A
Replies: 1 comment
-
|
this is because the type definition expects full object. you can fix it by casting: const { defineField, errors, handleSubmit, setErrors } = useForm({
initialErrors: {} as Partial<Record<keyof z.infer<typeof FormLoginSchema>, string>>,
initialValues: { email: "", password: "" },
name: "form-login",
validationSchema: FormLoginSchema,
});or just dont pass initialErrors if its empty: const { defineField, errors, handleSubmit, setErrors } = useForm({
initialValues: { email: "", password: "" },
name: "form-login",
validationSchema: FormLoginSchema,
});if you need to set errors later use setErrors instead: setErrors({ email: "some error" })the initialErrors type is strict because it validates at compile time that youre not setting errors for fields that dont exist |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
i don't understand why useForm's initialErrors property in a typescript context insists on all fields being required. For the life of me i can't convice the useForm composable to treat initialErrors as PARTIAL
Beta Was this translation helpful? Give feedback.
All reactions