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

241
Vistas
How to make Yup field which is object, required if other field is true. -Yup validation

I'm new to using Yup validation. I'm trying to achieve making fields required based on condition. as u can see below I want to make this digital object required only if hasDigital is true other wise keep it optional, I tried below approach but it always says digital.pages is required , even when I'm passing hasDigital false. I tried by removing required tag from hasDigital but still facing same issue.

I don't know what am I doing wrong, thanks In advance for any help.

const validationSchema=Yup.object({
  hasDigital:Yup.boolean().required(),
  digital:Yup.Object({
    pages:Yup.number().required(),
    price:Yup.number().required()
    }).when("hasDigital", {
        is:true ,
        then: Yup.object().required(),
        otherwise:Yup.object().optional()})
})
about 4 years ago · Juan Pablo Isaza
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