Last active
September 17, 2021 13:39
-
-
Save diegoarcega/b134e2f3ec17bf0703c29cf25cf43caf to your computer and use it in GitHub Desktop.
yup object validation
This file contains 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
// when you have a checkbox and want to validate that at least one of the options is selected | |
patientMedicalConditions: yup | |
.object({ | |
dizziness: yup.bool(), | |
diabetes: yup.bool(), | |
neuropathy: yup.bool(), | |
historyOfStroke: yup.bool(), | |
arthritis: yup.bool(), | |
signsOfBoneDeterioration: yup.bool(), | |
}) | |
.test('at-least-one', 'Select at least one option', (valueObject) => { | |
return Object.values(valueObject).some((value) => !!value); | |
}), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment