我正在使用Jquery smartwizard link,我需要在用户点击任何步骤中的“上一步”按钮时停止验证(默认情况下,在第一步中禁用上一步按钮),第一步除外。
这是我的javascript代码
$(document).ready(function () {
// Smart Wizard
$('#wizard').smartWizard({
transitionEffect: 'fade',
onLeaveStep: leaveAStepCallback,
onFinish: onFinishCallback,
enableFinishButton: false
});
function leaveAStepCallback(obj) {
var step_num = obj.attr('rel');
return validateSteps(step_num);
}
function onFinishCallback() {
if (validateAllSteps()) {
$('form').submit();
}
}
});
function validateAllSteps() {
var isStepValid = true;
if (validateStep1() == false) {
isStepValid = false;
$('#wizard').smartWizard('setError', {
stepnum: 1,
iserror: true
});
} else {
$('#wizard').smartWizard('setError', {
stepnum: 1,
iserror: false
});
}
if (validateStep2() == false) {
isStepValid = false;
$('#wizard').smartWizard('setError', {
stepnum: 2,
iserror: true
});
} else {
$('#wizard').smartWizard('setError', {
stepnum: 2,
iserror: false
});
}
if (validateStep3() == false) {
isStepValid = false;
$('#wizard').smartWizard('setError', {
stepnum: 3,
iserror: true
});
} else {
$('#wizard').smartWizard('setError', {
stepnum: 3,
iserror: false
});
}
if (!isStepValid) {
$('#wizard').smartWizard('showMessage', 'Please correct the errors in the steps and continue');
}
return isStepValid;
}
function validateSteps(step) {
var isStepValid = true;
// validate step 1
if (step == 1) {
if (validateStep1() == false) {
isStepValid = false;
$('#wizard').smartWizard('showMessage', 'Please correct the errors in step' + step + ' and click next.');
$('#wizard').smartWizard('setError', {
stepnum: step,
iserror: true
});
} else {
$('#wizard').smartWizard('hideMessage');
$('#wizard').smartWizard('setError', {
stepnum: step,
iserror: false
});
}
}
// validate step2
if (step == 2) {
if (validateStep2() == false) {
isStepValid = false;
$('#wizard').smartWizard('showMessage', 'Please correct the errors in step' + step + ' and click next.');
$('#wizard').smartWizard('setError', {
stepnum: step,
iserror: true
});
} else {
$('#wizard').smartWizard('hideMessage');
$('#wizard').smartWizard('setError', {
stepnum: step,
iserror: false
});
}
}
// validate step3
if (step == 3) {
if (validateStep3() == false) {
isStepValid = false;
$('#wizard').smartWizard('showMessage', 'Please correct the errors in step' + step + ' and click next.');
$('#wizard').smartWizard('setError', {
stepnum: step,
iserror: true
});
} else {
$('#wizard').smartWizard('hideMessage');
$('#wizard').smartWizard('setError', {
stepnum: step,
iserror: false
});
}
}
return isStepValid;
}
function validateStep1() {
//Validation code here
}
function validateStep2() {
//Validation code here
}
function validateStep3() {
//Validation code here
}
答案 0 :(得分:0)
......一个非常合理的要求。试试这个......
function leaveAStepCallback(anchor, context) {
//var step_num = obj.attr('rel');
if(context.toStep > context.fromStep)
return validateSteps(fromStep);
else
return true;
}
docs建议您可以从第二个参数获取Step和toStep,如图所示。我希望是这样的!如果没有,就去寻找它。它必须在某处。
答案 1 :(得分:0)
您可以检查从步骤到步骤:
function nextStep(smartWizard, steps, context){
if(steps.fromStep == 1 && steps.toStep == 2){
// Do validations
}
}
我使用了以下向导:
$('#wizard').smartWizard({
onLeaveStep: nextStep // triggers when leaving a step
});