2013-10-25 23 views
0

我在我的項目中使用智能嚮導讓用戶在我的網站上註冊。但是我想在步驟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(); 
} 

回答

0

修改插件,讓你有另一個按鈕,說「保存部分」。然後添加一個叫做「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(); 
} 

NB你必須破解插件它顯示的按鈕,來處理onSavePartial啄

+0

我做到了以另一種方式,並嘗試過這種方式。謝謝。 – koli

1

您可以綁定到「上一步離開事件「的智能精靈

$("#smtwrdConf").on("leaveStep", function (e, anchorObject, stepNumber, stepDirection) { 
    //you can perform step-by-step validation 

if(validatestep) }

,如果下一步= STEPNUMBER + 2 == 4,提交表單

相關問題