This is a snippet in my React application using Formik.
My initial value is
initialValues: {
country: { label: '', value: '' }
}
My field input is country
which is a Select
option and its value when selected will be as
country: { label: 'India', value: 'India' }
My required error
object when a country
is not selected should be
{ country: "Please select a country" }
How can I add a yup validation to get my required error when a country is not selected, or in other means when country.value === ''
?
I wrote a validation like this
country: yup.object().shape({
value: yup
.string()
.label('Country')
.required("Please select a country"),
})
which is wrong and this gives the error object as country: { value: "Please select a country" }
which is not as my requirement.
What changes should I do here?