Skip to content

Multiple alternatives with default #763

@2j2e

Description

@2j2e

Imagine than we have a,b,c fields.

a: Joi.string().required(),
b: Joi.any()
    .when('a', {is: 'Other', then: Joi.any(), otherwise: Joi.string().required()}),
c: Joi.alternatives()
    .when('a', {is: 'Other', then: Joi.string().required()})
    .when('b', {is: 'Other', then: Joi.string().required()})

a - is always required.
b - required only if a != 'Other'
c - required only if a == 'Other' OR b == 'Other'

If none of c rules has been applied c should be optional()
How should I rebuild my schema to get last rule working?

Metadata

Metadata

Assignees

Labels

breaking changesChange that can breaking existing codebugBug or defect

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions