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

212
Visualizações
Handling undefined text input value

I have this condition here that checks if the value is undefined

console.log("Value: " + typeof getValues('departmentId'))
if (String(getValues('departmentId')) != "" ||
    String(getValues('departmentDesc')) != "" ||
    typeof getValues('departmentId') !== undefined ||
    typeof getValues('departmentDesc') !== undefined){
    dispatch(setIsConfirm(true))
    console.log("Clearing fields || Value: " + getValues('departmentId'))
}

But for some reason it still ran even though it is undefined, here is the picture of the console

about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

typeof returns a string. So you need to do this instead:

console.log("Value: " + typeof getValues('departmentId'))
if (typeof getValues('departmentId') !== "undefined" || typeof getValues('departmentDesc') !== 'undefined'){
    dispatch(setIsConfirm(true))
    console.log("Clearing fields || Value: " + getValues('departmentId'))
}

Also, make sure you really need OR || operator and not AND &&. Replace it if needed.

about 4 years ago · Santiago Gelvez Relatório

0

I went with this:

  if ((String(getValues('departmentId')) !== "" && typeof getValues('departmentId') !== "undefined") ||
            (String(getValues('departmentDesc')) !== "" && typeof getValues('departmentDesc') !== "undefined")){
            dispatch(setIsConfirm(true))
        }
about 4 years ago · Santiago Gelvez 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