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

129
Views
How to wait for validation and then return the result in old JavaScript code?

I'm using jQuery-steps in a legacy codebase.

The point is, I'm trying to make it dynamic and I'm stuck at asynchronistic nature of form validation.

This plugin creates a multi-step form, and you can click next to navigate to the next tab.

However, there is this onStepChanging: function (event, currentIndex, priorIndex) function that can be used to prevent navigation to the next tab, if form is invalid.

It works great for synchronous fields. That is, this code works great:

onStepChanging: function (event, currentIndex, newIndex) {
    if ($('#username').val() === '') {
        return false;
    }
    return true;
}

But this code does not work:

onStepChanging: function (event, currentIndex, newIndex) {
    fetch('/validate?username='  + $('#username').val())
    .then(function(result) {
        if (result == 'valid') {
            return true;
        }
        return false;
    });
}

This second code does not work, because it does not wait for the result of the fetch method.

How can I force it to wait for the result of fetch, and then return?

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