我正在使用Jquery smartwizard link,我需要停止驗證,當用戶在任何步驟中單擊「上一步」按鈕(默認情況下在第1步中上一個按鈕被禁用)除第1步。如何跳過驗證時向後 - SmartWizard
這裏是我的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
}
檢查此鏈接http://stackoverflow.com/questions/9925255/skip-validation -when-back-in-smartwizard – Suyog