[jQuery] asynchronous validation + BabySteps
Hi,
I am struggling a bit with this. I am using the 'jQuery BlockUI
Plugin' and the 'BabySteps' plugin (http://blog.vokle.com/index.php/
2008/08/22/babysteps/) where I go from step to step if the previous
step validates ok. I have (simplified) code like this:
step1.bindStep(step2, { nextValidator: step1_validator, transition:
function(currStep, nextStep) { currStep.slideUp(); nextStep.slideDown
(); } });
function step1_validator() {
$.ajax({
url: "../a/b",
type: "POST",
dataType: "text",
data: { },
async: true,
error: function(XMLHttpRequest, textStatus,
errorThrown) {
showErrorMessage(Server error " + textStatus + " "
+ errorThrown);
},
beforeSend:
function(data) {
$.blockUI({ message: 'Please wait ...' });
},
success: function(data) {
data = JSON.parse(data);
$.unblockUI();
if( !(data.message=="") )
{
showErrorMessage(data.message);
return false;
}
else
{
return true;
}
}
});
}
The step1_validator should return true or false depending on whether
the validation is ok of not. I have to use server side validation and
make an asynchronous request. Ideally I would like my 'mother
function' (step1_validator) to wait for the asynchronous request to
finish and return true or false depending on 'if( !
(data.message=="") )'. I hope this makes sense. I can set async: to
false but then $.blockUI({ message: 'Please wait ...' }); dose not
work anymore.
Looking forward to hearing from you.
Best wishes,
Christian