jqueryasp.net-mvc-3smart-wizard

Skip validation when going backwards in SmartWizard


I am using the SmartWizard 2.0 (link) and I need to stop the validation from kicking in when the users hits the "Prev" button or in any way moves backward in the form.

Currently I am using

// Triggers whenever you change page/tab in wizard    
function leaveStep(obj) {        
    $("form").validate();
    if ($("form").valid())
        return true;

    return false;
}

I know that I can use

var currentStep = obj.attr('rel'); // get the current step number

to find the currentStep, but I need to know which way the user is navigating - so I need to know the "nextStep". Don't know if this is possible.


Solution

  • When onLeaveStep is triggered could you not use the obj to determine the direction? Then you would only validate when moving to the next step?

    Updated:

    After looking at the source code, there is no way that I can see to figure out the direction. Patching in the ability is pretty easy however. In jquery.smartWizard-2.0.js change line 186 from

    if(!options.onLeaveStep.call(this,$(curStep))){
    

    to

    if(!options.onLeaveStep.call(this,$(curStep),$(selStep))){
    

    This now gives you access to the selected step anchor, and thus the selected step index. To determine the direction in your onLeaveStep handler simple do the following:

    // Triggers whenever you change page/tab in wizard    
    function leaveStep(from, to) {
        var fromStepIdx = from.attr( "rel" );
        var toStepIdx = to.attr( "rel" );
    
        if ( toStepIdx < fromStepIdx )
        {
            return true;
        }
    
        $("form").validate();
        if ($("form").valid())
            return true;
    
        return false;
    }