Skip to content
Advertisement

Joi validate at least one of 2 input fields are completed

I seem to hit a roadblock when it comes to joi’s .or() function as it doesn’t seem to implement as I’d expect.

I have 2 text input fields, both have their own way of validating, though only at least one is required.

JavaScript

it just seems that this or doesn’t do as I’d expect and each field from the or is just validated as per it’s own validation rules

if neither field has values, then I’ll display error for both fields until at least one is completed

Advertisement

Answer

From here

JavaScript

alternatives().try() adds an alternative schema type for attempting to match against the validated value. You are passing two options and it will choose one of them.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement