I am using formik and Yup to handle by form data and Form Validation in react . I am trying to change the value of "Showfile" to true to do conditional validation But value is not changing.
TextField
label="Resume"
star="*"
color="red"
name="file"
type="file"
accept=".pdf ,.docx,.doc "
onChange={(event) =>
formik.setFieldValue(
"file",
event.currentTarget.files[0],
"showfile",
true
)
}
value={formik.value}
/>
file: Yup.mixed().when("showfile", {
is: true,
then: Yup.mixed()
.required("Required")
.test(
"FILE_SIZE",
"Uploaded file is too big.",
(value) => value && value.size value && SUPPORTED_FORMATS.includes(value.type)
),
Formik
initialValues={{
UserName: "",
email: "",
Phone: "",
message: "",
file: "",
showfile: false,
submit: false,
}}
validationSchema={validate}
onSubmit={(values, actions) => {
setTimeout(() => {
console.log(values);
actions.setSubmitting(false);
}, 1000);
}}
>