Yup

node v6.17.1
version: master
endpointsharetweet
const yup = require('yup'); const schema = yup .object({ red: yup.boolean(), orange: yup.boolean(), green: yup.boolean() }) .test( 'myCustomTest', null, (obj) => { if ( obj.red || obj.orange || obj.green ) { return true; // everything is fine } return new yup.ValidationError( 'Please check at least one checkbox', null, 'myCustomFieldName' ); } ); const validateOptions = { abortEarly: false }; null;
const testValues1 = { red: false, orange: false, green: false }; await schema.validate(testValues1, validateOptions) .then(() => { return true }) .catch((err) => err.errors);
const testValues2 = { red: true, orange: false, green: false }; await schema.validate(testValues2, validateOptions) .then(() => { return true }) .catch((err) => err.errors);
Loading…

no comments

    sign in to comment