Skip to content

Instantly share code, notes, and snippets.

@diegoarcega
Last active September 17, 2021 13:39
Show Gist options
  • Save diegoarcega/b134e2f3ec17bf0703c29cf25cf43caf to your computer and use it in GitHub Desktop.
Save diegoarcega/b134e2f3ec17bf0703c29cf25cf43caf to your computer and use it in GitHub Desktop.
yup object validation
// 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