27

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?

$(function () {
    $("#wizard").steps({
        headerTag: "h2",
        bodyTag: "section",
        transitionEffect: "slideLeft",
        enableFinishButton: false,
        labels: {
            next: $('#next').html(),
            previous : $('#previous').html()

        },
        onStepChanged: function (event, currentIndex, priorIndex)
        {
            if( priorIndex == 0) {
                var selected = $('input[name=radio_wizard]:checked', '#radio_wizard').val()
                switch( selected ){
                    case 1:
                        // GOTO 1 
                        break;
                    case 2:
                        // GOTO 2 
                        break;
                    case 3:
                        // GOTO 3 
                        break;
                }
            }
      }
}

How to achieve this?

Rafael Staib
  • 1,226
  • 12
  • 14
Capuchin
  • 3,465
  • 6
  • 28
  • 40

16 Answers16

33

I did this so I created this new function:

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

And the call that is not implemented, put this:

$.fn.steps.setStep = function (step)
{

    var options = getOptions(this),
        state = getState(this);

    return _goToStep(this, options, state, step);

};

Just taking advantage of what already existed plugin.

Use:

wizard.steps("setStep", 1);
Fernando Tholl
  • 2,587
  • 2
  • 16
  • 14
  • 8
    Why don't you submit this as a pull request? – tutuDajuju Dec 19 '13 at 14:00
  • 2
    For all I want to mention to be careful to change the signature from `function(index,step)` to the `function(step)` above mentioned by @Fernando Tholl – Cristian E. Jan 30 '14 at 11:45
  • I added this to my steps plugin file, but still complaining and says not yet implemented! Any idea? Thanks – ZAD May 06 '16 at 15:38
  • 2
    Same for me : Inside $.fn.steps.setStep, it says that 'getOptions' is not implemented. I have a hard time picture what is the "this" and the scope of setStep's body, and to which object getOptions is supposed to belong. – jeancallisti Jul 02 '18 at 16:52
21

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.

Santosh Panda
  • 7,235
  • 8
  • 43
  • 56
Matthew Friedman
  • 491
  • 1
  • 5
  • 12
20

stepsWizard = $("#wizard").steps({
        forceMoveForward : true,
        enablePagination: false,
        titleTemplate : '<span class="number">#index#.</span> #title#'
    });

stepsWizard.steps("next"); // this will send us on next step :-)
Code Maverick
  • 20,171
  • 12
  • 62
  • 114
Abdul Jamal
  • 366
  • 3
  • 6
19

You can create a custom implementation with a simple loop:

$.fn.steps.setStep = function (step)
{
  var self = $(this);
  var currentIndex = self.steps('getCurrentIndex');
  // Calculates the number of missing steps to get to the desired step
  var missingSteps = Math.abs(step - currentIndex);
  // The method then determines whether to navigate forward or backward to the desired step by checking if the step parameter is greater than the current index
  var direction = step > currentIndex ? 'next' : 'previous';
  // Move forward or backward by one step each time the loop runs, until it reaches the desired step
  for(var i = 0; i < missingSteps; i++){
    self.steps(direction);
  } 
};

And you can execute this new method in the below way:

$("#form").steps("setStep", 4); //based on 0 (set the index)
jdnichollsc
  • 1,520
  • 1
  • 24
  • 44
5

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!"); 
};
Code Maverick
  • 20,171
  • 12
  • 62
  • 114
5

Basing on @AbdulJamal answer, I've implemented it for any step:

$(function () {
    var stepsWizard = $("#wizard").steps({
        ...
    });

    // step variable handles current step (from 0)
    for(var i=0; i<step; i++) {
        stepsWizard.steps("next");
    }
});

Note that step variable must be defined and equal or greater than 0.

Manolo
  • 24,020
  • 20
  • 85
  • 130
  • This will trigger the stepping events every step of the way. A way to go directly to the desired step seem like a better solution. – Benyamin Shoham Jun 10 '18 at 16:46
2

I did something like below to get it worked:

stepsWizard = $("#wizard").steps({
    headerTag: "h2",
    bodyTag: "section"
});

var indx = 3;
for (i = 0; i <= indx; i++) {
 stepsWizard.steps("next");
}
Mohamed Thaufeeq
  • 1,667
  • 1
  • 13
  • 34
2

Created this new function:

function _goToStep(wizard, options, state, index)
{
    return paginationClick(wizard, options, state, index);
}
And the call that is not implemented, put this:

Call that is not implemented, put this:

$.fn.steps.setStep = function (step)
{

    var options = getOptions(this),
        state = getState(this);

    return _goToStep(this, options, state, index); //Index Instead step

};

wizard.steps("setStep", 1);

works just fine

2

enter image description here

take the id of the step you want go and add a trigger!

$("#steps-uid-0-t-1").trigger("click");
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
1
function GotoSpecificStep(action, currentStep, number) {
    try
    {
        var stepsTogo = parseInt(currentStep) - parseInt(number);
        for (i = 1; i <= Math.abs(parseInt(stepsTogo)) ; i++) {
            if (action == "next") {
                $(".btnNext").click();
            }
            else if (action == "prev") {
                $(".btnPrevious").click();
            }
        }
    }
    catch(exception)
    {
        MsgBox(exception.message);
    }
}
Avshalom
  • 8,657
  • 1
  • 25
  • 43
0

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
  }
});
iled
  • 2,142
  • 3
  • 31
  • 43
Steve
  • 3
  • 2
0

Another simple solution:

var desiredStep = 0;
$("#steps-uid-0-t-" + desiredStep).click();
tomloprod
  • 7,472
  • 6
  • 48
  • 66
0
onInit: function(event) {
        let div = event.currentTarget;
        let lis = div.getElementsByTagName('li');
        // Choose second tab
        // active is just show style, only effective after clicking tag a.
        lis[1].className += ' active';
        $(lis[1]).children('a').click();
    }
YL Mei
  • 1
0

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);

Satpal
  • 132,252
  • 13
  • 159
  • 168
0

This is the simplest solution i found.

  1. Find your tablist item id (in my case it is '#ef_users_list-t-')
  2. Trigger click event
var tablist_item = 'ef_users_list-t-';

var step = 2; // step number to jump to
$(tablist_item+step).trigger('click');
Usman
  • 162
  • 2
  • 10
-1
jQuery('#multisteps_form').steps(
{
    headerTag: "h3",
    bodyTag: "section",
    transitionEffect: "slideLeft",
    autoFocus: true,
   // startIndex:2,

    onStepChanging: function() 
    {
        var myform=jQuery('#multisteps_form').serializeArray();
        
        jQuery.ajax({
                url: ajx_url,
                type: 'post',
                data: 
                {
                    'action':'final_submit_data',
                    myform:myform,
                },
                success: function (form_res) 
                {
                    jQuery('#form_submit').html(form_res);
                }
            });
        
        return true; // Most Important
    },
    onFinishing: function() 
    {
        
    },
    onFinished: function() 
    {
    
    }
});
  • This is Perfectlly working in My System ... Just check sure u will get idea of it.... U need to add CDN Link or custom CDN link For it .. – Mahesh Barot Dec 06 '21 at 13:00