I'm using the plugin http://www.jquery-steps.com/ and per documentation I should return true
to allow a user to pass to the next slide. I'm verifying if the zip code exists in our database. Only when the server verifies that the ZIPCode exists in our database the user is allowed to click next
.
What I tried
onStepChanging: function (event, currentIndex, newIndex) {
if(currentIndex == 2){
getZipCode($("#zip").val()).done(function(returnedData){
if(returnedData.length > 0){
return true;
}else{
setHelperText($("#zip_helper"), 'Zip Code doesn\'t exists in our database. Pick the closest one please');
}
}).fail(function () {
setHelperText($("#zip_helper"),'There was an error connecting to our servers');
});
return false;
}
}
function getZipCode(zip_code) {
return $.get('../ajax/zip-code', {
q: zip_code
});
}
What I expect
User may be able to click next only when the ZIPCode exists in our database.
From what I have read online the problem is that I'm returning return false
at the end thus the script is always returning false. How can I return true
inside of .done()
to be applicable to the outside scope?