I have an autocomplete that should be required if either of the two fields is true. My problem is that when I click submit, it outputs An unhandled error was caught during validation in <Formik validationSchema /> TypeError: You cannot
concat() schema's of different types: string and object
category: string().when(['new', 'exist'], {
is: false,
then: object({
id: string(),
name: string(),
})
.nullable()
.required('field is required'),
}),
new: bool().nullable(),
exist: bool().nullable(),
If I'm reading the error message correctly, then it seems that the string()
you have immediately after category:
should be replaced with object()
instead, ie:
category: object().when(['new', 'exist'], {
is: false,
then: object({
id: string(),
name: string(),
})
.nullable()
.required('field is required'),
}),
new: bool().nullable(),
exist: bool().nullable(),
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.