• Empleos
  • Sobre nosotros
  • Empleos
    • Inicio
    • Empleos
    • Cursos y retos
  • Empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

141
Vistas
Validation using joi with external schema

So, i'm trying to validate if a field is required given a specific scenario. Like this:

cake: Joi.object().keys({
            flavor: Joi.string().max(45).required(),
            price: Joi.string().length(2).required(),
            topping: Joi.string().length(2).required()
})

and in the same schema i have:

authentication: Joi.object().keys({
      password: Joi.string().max(45).required(),
      login64: Joi.string().max(45).required()
})

and i want to make a validation like:

authentication: Joi.object().keys({
      password: Joi.string().max(45).required(),
      login64: Joi.string().max(45).when('cake.flavor', {
      is: 'chocolate',
      then: Joi.required()

} })

i want to make login64 required if the flavor of the cake is chocolate. But nothing seems to work...

over 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

A Joy reference is by default relative to the parent of the current value, which in your case is authentication. You need to move a couple of levels up (...) in order to reach cake:

login64: Joi.string().max(45).when('...cake.flavor', {
    is: 'chocolate',
    then: Joi.required()
})
over 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda