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

154
Views
Multiple conditionals in one line for Javascript

I am learning React and Javascript. So far it's quite easy but when it comes to resolve how to validate multiple values for an input and print and error I cannot resolve it with conditional operators.

I have this react-hook-form component with 3 validation requirements: required, minLength and pattern:

<Input
  {...register('password', {
    required: true,
    minLength: minChars,
    pattern: passwordValidation,
    })}
    type='password'
    label={t('common:forms.password')}
    placeholder={t('common:forms.min_char', {
      count: minChars,
    })}
    errors={
           errors.password
             && errors.password.type === 'minLength'
             ? errors.password.type === 'required'
             ? errors.password.type === 'minChars'
                    ? true
                    : true
                  : ''
              }
            />

I want to print the true value if any or all 3 validations are active. I tried something like:

{errors.password ? true : ''}

And doesn't work

Also this one fails

{errors.password && errors.password.type === 'minLength' &&  errors.password.type === 'required' && errors.password.type === 'minChars' ? true : ''}

Maybe i cannot resolve this with conditional operators and i need to abstract this validation elsewhere or use yup.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I want to print the true value if any or all 3 validations are active.

Then you should use the logical OR operator || instead of AND && :

{errors.password && (errors.password.type === 'minLength' || errors.password.type === 'required' || errors.password.type === 'minChars') ? true : ''}
about 4 years ago · Santiago Trujillo Report
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!