Created
August 5, 2019 09:44
-
-
Save meetzaveri/e0f70fcd571bd8d01dfc8a219c7da2df to your computer and use it in GitHub Desktop.
Typical validations for formik Yup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Typical dependent validations in formik | |
```js | |
minimum_requirement_datas: Yup.number() | |
.nullable() | |
.when(['minimum_requirement'], { | |
is: value => value == 'purchaseAmount' || value == 'itemQuantity', // alternatively: (isBig, isSpecial) => isBig && isSpecial | |
then: Yup.number() | |
.nullable() | |
.required('Required'), | |
otherwise: Yup.number().min(0) | |
}), | |
customer_eligibility: Yup.string().required('Required'), | |
applies_to: Yup.string() | |
.required('Required') | |
.nullable(), | |
// applies_datas: Yup.string().nullable(), | |
usage_limits: Yup.number() | |
.nullable() | |
.when(['is_checked_usage_limits'], { | |
is: true, // alternatively: (isBig, isSpecial) => isBig && isSpecial | |
then: Yup.number() | |
.nullable() | |
.required('Required'), | |
otherwise: Yup.number().min(0) | |
}), | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment