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

213
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
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