Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
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...

about 4 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()
})
about 4 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda