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

277
Vistas
Yup validation that only one element from the object schema is required

Having the following schema:

const schema = yup.object().shape({
  val1: yup.string(),
  val2: yup.string(),
  val3: yup.string(),
  val4: yup.string(),
  val5: yup.string(),
  val6: yup.string(),
  val7: yup.string()
});

It is a way to make required at least one element of those, doesn't matter which one?

There is a solution with conditionally set but it doesn't seem to work for multiple elements, tried like this:

const schema = yup.object().shape(
  {
    val1: yup.string().when('val2', 'val3', 'val4', 'val5', 'val6', {
      is: '',
      then: yup.string(),
      otherwise: yup.string()
    }),
    val2: yup.string().when('val1', 'val3', 'val4', 'val5', 'val6', {
      is: '',
      then: yup.string(),
      otherwise: yup.string()
    })
   ...
  },
  [['val1', 'val2', 'val3', 'val4', 'val5', 'val6']]
);
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