Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set the second value when a required field is validated? #3067

Open
Du-Nguyen opened this issue Feb 25, 2025 · 0 comments
Open

How to set the second value when a required field is validated? #3067

Du-Nguyen opened this issue Feb 25, 2025 · 0 comments
Labels
support Questions, discussions, and general support

Comments

@Du-Nguyen
Copy link

Runtime

Node js

Runtime version

Node 18

Module version

"joi": "^17.13.3",

Used with

No response

Any other relevant information

No response

How can we help?

When validating, if the value does not exist, set the second value from an environment variable; if it is still unavailable, make it required.
I tried implementing it as below, and it seems to work. Is it okay?

 var: Joi.string()
        .required()
        .failover(() => process.env.VAR),
@Du-Nguyen Du-Nguyen added the support Questions, discussions, and general support label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

1 participant