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

203
Views
how can i access the path and see the message of an error returned using JOI validation

i'm trying to use joi validation method and i can't access the path or message returned from the object i tried to follow some videos to know more yet no effects the whole problem is that i can't access the joi object though it's consoled correctly

    state ={
    username : "",
    password : "",
    errors :{}
};


schema =Joi.object().keys({
    username: Joi.string().required(),
    password:Joi.string().required()
})

validate = ()=>{
    const errors = {};
            const res = Joi.validate(this.state,this.schema,{abortEarly:false});
    console.log(res);        
    if (res.error===null ){
        this.setState({errors:{}});
        return null;
    }
    // this is where i get the error and can't access it 
    for (const error of res.error.details){
        errors[error.path] = error.message;
    }
    this.setState({errors});

}
handleSubmit=(e)=>{
    e.preventDefault();
    const errors = this.validate();
    if(errors){return}
    else{
        //call backend
        console.log("Passed");
    }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Hopefully you have already figured it out now🙂 However, just in case, if you are using the lastest version of Joi, then if you look at the document, you will find the validate method now is being called on the schema, not the Joi object itself, which means you can do it like Schema. validate() instead of Joi.validate(). Alright, happy coding :)

about 4 years ago · Juan Pablo Isaza 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!