我在我的项目中使用SmartWizard来让用户注册到我的网站。但是我想在向导有四个步骤的步骤 3 中保存所有数据。向导在单击完成按钮后提交表单。下面的代码将描述我的假设,任何人都可以建议一种方法来做到这一点。谢谢。
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});
}
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('setError',{stepnum:step,iserror:false});
}
}
// validate step 2
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('setError',{stepnum:step,iserror:false});
}
}
return isStepValid;
}
//start of step one validation
//end of of step one validation
//step 2 validation
//end of step 2 validation
var res=validateAllSteps();
if(res == true)
{
$('#form1').submit();
}
可以绑定到智能向导的"踏步离开事件"
$("#smtwrdConf").on("leaveStep", function (e, anchorObject, stepNumber, stepDirection) {
//you can perform step-by-step validation
if(验证步骤) }
如果下一步 = 步数+2 == 4,请提交表格
修改插件,以便您将拥有另一个按钮,说"保存部分"。然后添加一个称为"onSavePartial"的事件处理程序。在插件初始化期间,您可以添加要调用的回调。然后在此回电中提交您的表格。
jQuery('#wizard').smartWizard({
selected:currentStep,
enableAllSteps:enableSteps,
transitionEffect:'slideleft',
onLeaveStep:leaveAStepCallback,
onFinish:onFinishCallback,
onSavePartial:onSavePartialCallBack,
enableFinishButton:false,
});
这是 onSavePartialCallBack 函数
function onContinueLaterCallback(){
//your validation and other stuff here
jQuery('form').submit();
}
注意你必须破解插件才能显示按钮,并处理保存部分的东西