Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda