Skip to content

Instantly share code, notes, and snippets.

@up209d
Created October 9, 2019 00:41
Show Gist options
  • Save up209d/4735312ce800191062b6b6728af2d5b2 to your computer and use it in GitHub Desktop.
Save up209d/4735312ce800191062b6b6728af2d5b2 to your computer and use it in GitHub Desktop.
Yup test reading values from current form state
export default yup.object().test('bothFieldsCannotBeEmpty', 'Both fields cannot be empty', values => {
const { matchingInclusionRule, matchingExclusionRule } = values;
return (
!!matchingInclusionRule ||
!!matchingExclusionRule ||
new yup.ValidationError(`Inclusion Rule & Exclusion Rule cannot be left both empty.`, null, 'matchingInclusionRule')
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment