Going to a custom step with jQuery-steps

前端 未结 15 1065
粉色の甜心
粉色の甜心 2020-12-28 16:46

I am using a jQuery-steps on my app to for a wizard-like situation. I am having trouble finding out how to change to a custom step though. Any help with this one?

         


        
相关标签:
15条回答
  • 2020-12-28 16:53

    I found a simple way to do this. you can use the jquery function

    $("#wizard-t-2").get(0).click();
    

    assuming you know what step you want to go to. this example would bring you to the third step of the wizard. use chromes editor to figure out what the exact id is of the step you want to go to.

    0 讨论(0)
  • 2020-12-28 16:53

    Adding to the answer above by @FernandoTholl, for clarification, wizard.steps("setStep", 1); goes in onStepChanged

    $('#wizard').steps({
      onStepChanging: function (event, currentIndex, newIndex) {
          //blah, blah, blah, some code here
      },
      onStepChanged: function (event, currentIndex, newIndex) {
        $('#wizard').steps("setStep", 3);
      },
      onFinished: function () {
          ///more code
      }
    });
    
    0 讨论(0)
  • 2020-12-28 16:54

    Another simple solution:

    var desiredStep = 0;
    $("#steps-uid-0-t-" + desiredStep).click();
    
    0 讨论(0)
  • 2020-12-28 16:57

    stepsWizard = $("#wizard").steps({
            forceMoveForward : true,
            enablePagination: false,
            titleTemplate : '<span class="number">#index#.</span> #title#'
        });
    
    stepsWizard.steps("next"); // this will send us on next step :-)

    0 讨论(0)
  • 2020-12-28 17:00

    Based on the documentation, it seems to lack that functionality as of right now:

    /*  
     * Sets a specific step object by index.  
     *  
     * @method setStep  
     * @param index {Integer} An integer that belongs to the position of a step  
     * @param step {Object} The step object to change  
     *
     */
    $.fn.steps.setStep = function (index, step) 
    {
        throw new Error("Not yet implemented!"); 
    };
    
    0 讨论(0)
  • 2020-12-28 17:02

    I did this so I created this new function in jquery.steps.js, is important inserts before the $.fn.steps.setStep function:

    function _goToStep(wizard, options, state, index)
    {
        return paginationClick(wizard, options, state, index);
    }
    

    In jquery.steps.js find the $.fn.steps.setStep = function and replace then with:

    $.fn.steps.setStep = function (step)
    {
    
        var options = getOptions(this),
            state = getState(this);
    
        return _goToStep(this, options, state, step);
    
    };
    

    Use:

    wizard.steps("setStep", 1);

    0 讨论(0)
提交回复
热议问题