0

I,m using SmartWizard in my project for getting the user registered with my web site. But i want to save all the data at the step 3 where the wizard has four steps. The wizard submits the form after clicking the finish button. Below code will describe my assumptions and can any one suggest a way to do this. Thanks.

    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();
}
koli
  • 194
  • 1
  • 6
  • 24

2 Answers2

2

You can bind to "on step leave event" of smart wizard

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

if(validatestep) }

and if the next step = stepnumber+2 == 4, submit the form

0

Modify the plugin so that you will have another button, say "save Partial". Then add an event handler that is called something like "onSavePartial". During initalization of the plugin u can add the callback to be called. Then submit your form inside this call back.

 jQuery('#wizard').smartWizard({
 selected:currentStep,
 enableAllSteps:enableSteps,
 transitionEffect:'slideleft',
 onLeaveStep:leaveAStepCallback,
 onFinish:onFinishCallback,
 onSavePartial:onSavePartialCallBack,
 enableFinishButton:false,
 });

And here is the onSavePartialCallBack Function

function onContinueLaterCallback(){
    //your validation and other stuff here

    jQuery('form').submit();
}

NB You have to hack the plugin for it to show the button, and to handle onSavePartial thingy

Tom Mwenda
  • 155
  • 3
  • 16