I want to validate file input if a file is selected, I found the solution for Formik/Yup but it validates even if file is not selected.
avatar: Yup.mixed()
.test("fileSize", "File is too large", value => {
return value && value.size <= FILE_SIZE;
})
.test(
"fileFormat",
"Unsupported Format",
value => value && SUPPORTED_FORMATS.includes(value.type)
)
It triggers validation when I type in other inputs, I want to trigger it only if file is there since avatar is optional!
notRequired()
? – Dani Vijay