0

I'm trying to use the jQuery Wizard SmartEizard 3.0 which has a 'goToStep' method allowing you to jump to a given step based on a logic. I tried it with the below code but it seems to get stuck in an infinite loop and never goes to the next step. Can anyone spot what i'm doing wrong here?

  $(document).ready(function () {

        // Smart Wizard     
        $('#wizard').smartWizard({
            enableFinishButton: false,
            onLeaveStep:onLeaveStepFunction,
            onFinish:onFinishCallback
        });

        function onLeaveStepFunction(obj, context) {
                .
                .
                .
                //when below is triggered, SmartWizard gets stuck in infinite loop
                if ('#addProfileCheckbox').prop('checked')){
                    $('#wizard').smartWizard('goToStep',4);                 
                }
                return true;
        }

        function onFinishCallback(){
            console.log('here ...');
        }

    });

In Chrome i can see it causing the page to crash and "stack limit exceeded' error.

ke3pup
  • 1,835
  • 4
  • 36
  • 66

2 Answers2

1

This happens because onLeaveStepFunction() is fired again when you call $('#wizard').smartWizard('goToStep',4), thus causing an infinite loop:

onLeave -> goToStep -> onLeave -> goToStep and so on.

Balansse
  • 13
  • 2
0
  // wizard 展示事件
    function onShowAStepCallBack(obj, context)
    {
        // 如果等于三
        if (context.fromStep == 3) {
            $('#order-store-st').removeClass('handing');
        }
        var is_censor = $("#order-store-nd input[name=is_censor]").prop('checked');
        var is_warrantor = $("#order-store-nd input[name=is_warrantor]").prop('checked');

        if(context.fromStep == 5 && is_censor && is_warrantor){
            $('#order_wizard').smartWizard('goToStep',2);  

         }
    }