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

211
Views
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 answers
Answer question

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 Report

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