Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

286
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!