I would like to combine to use zod and formik by using zod-formik-adapter When I do this:
const searchForm = useFormik<ChartSearch>({
initialValues: {...},
onSubmit: (value, action) => {
action.setSubmitting(true);
},
validationSchema: toFormikValidationSchema(chartSearchSchema),
});
const customGetDetailClick = (e: any) => {
try {
chartSearchSchema.parse(searchForm.values);
// do something
} catch (error: any) {
searchForm.setErrors(error);
}
};
where the I will render like this
<div className="d-flex align-items-center error-container">
{searchForm.touched.fieldError && Boolean(searchForm.errors.fieldError) && (
<span className="text-danger small">{searchForm.errors.fieldError}</span>
)}
</div>
I try to debug error value, and it will come this
[
{
"code": "custom",
"path": [
"fieldError"
],
"message": "Something wrong value defined"
}
]
But it can't to do on seterrors. can I know how to do it as I don't want to use searchForm.handleSubmit(); for this case