How to submit smart form wizard before come to last step

4.4k Views Asked by At

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();
}
2

There are 2 best solutions below

1
On

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

0
On

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