Reputation: 3990
Whats the best way to allow only two specified values in the selector, for example I have 2 fields for a user to select :
US
UGX
below is my code snippet :
Validations code :
const signUpSchema = Yup.object().shape({
countrySelector: Yup.string().required('Please select the country'),
});
JSX snippet
<Formik
validationSchema={signUpSchema}
onSubmit={handleSignUpAsync}
initialValues={{
countrySelector: '',
}}
>
<Form>
<Field
as="select"
className="browser-default custom-select"
name='countrySelector'>
<option value="-">-</option>
<option value="DE">DE</option>
<option value="US">US</option>
</Field>
</Form>
</Formik>
Upvotes: 7
Views: 4445