Going to a custom step with jQuery-steps

2019-01-22 19:39发布

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?

11条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-01-22 20:03

Check my following implementation, What do you think guys?

$.fn.steps.setStep = function (step)
{
  var currentIndex = $(this).steps('getCurrentIndex');
  for(var i = 0; i < Math.abs(step - currentIndex); i++){
    if(step > currentIndex) {
      $(this).steps('next');
    }
    else{
      $(this).steps('previous');
    }
  } 
};

And you can execute the new method very easy:

$("#form").steps("setStep", 4); //based on 0 (set the index)

Regards, Nicholls

查看更多
3楼-- · 2019-01-22 20:04

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);
查看更多
三岁会撩人
4楼-- · 2019-01-22 20:10

Another simple solution:

var desiredStep = 0;
$("#steps-uid-0-t-" + desiredStep).click();
查看更多
叛逆
5楼-- · 2019-01-22 20:12

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!"); 
};
查看更多
何必那么认真
6楼-- · 2019-01-22 20:13

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
  }
});
查看更多
聊天终结者
7楼-- · 2019-01-22 20:13

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");
}
查看更多
登录 后发表回答