hapijs / hapijs/joi

Are complex conditions (and/or/and) supported?

Open
#2,938 14 comments 0 reactions 0 assignees View on GitHub
support
Dominant language
JavaScript
Stars
21.2k
Forks
1.5k
Avg merge
4h 57m
Merged PRs (30d)
14

Description

#### Support plan

* *is this issue currently blocking your project?* yes, but not critically
* *is this issue affecting a production system?* (yes/no): no

#### Context

* *node version*: n/a
* *module version*: 17.9.1
* *environment* (e.g. node, browser, native): browser
* *used with* (e.g. hapi application, another framework, standalone, ...): react-hook-form
* *any other relevant information*: see below

#### How can we help?

We're building a form builder in our application with support for conditional fields. We've built the back-end API of our system and are now working on the [front-end piece](https://github.com/impress-org/givewp-next-gen/pull/157). Namely, if a field's conditions are false, then the field is not visible; if it is not visible, then it doesn't need to be validated.

I used `.when` to get a simple version of it working. But now that I'm looking through the docs, I'm realizing there doesn't seem to be a way of chaining complex conditions — `if A AND B OR C`. It looks like it's implicitly all AND conditions. I found [alternatives.match](https://joi.dev/api/?v=17.9.1#alternativesmatchmode), but it seems like that only supports "any", "all", or "one" modes — all of which apply to the whole chain.

It seems like Joi simply isn't capable of complex condition chains, but I wanted to reach out to confirm this.

Thank you!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.