Skip to content

Commit 8df104f

Browse files
ADD: option to disable (and re-enable) specific steps from being used when going Next and Previous
1 parent 44e1d42 commit 8df104f

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

build/jquery.steps.js

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,16 @@ function getValidEnumValue(enumType, keyOrValue)
456456
**/
457457
function goToNextStep(wizard, options, state)
458458
{
459-
return paginationClick(wizard, options, state, increaseCurrentIndexBy(state, 1));
459+
// Determine next active step
460+
var newIndex = increaseCurrentIndexBy(state, 1);
461+
do {
462+
if (typeof state.disabledSteps == 'undefined' || $.inArray(newIndex, state.disabledSteps) == -1) {
463+
break; //found an index that is not disabled => stop the loop
464+
}
465+
newIndex++;
466+
} while (true);
467+
468+
return paginationClick(wizard, options, state, newIndex);
460469
}
461470

462471
/**
@@ -472,7 +481,16 @@ function goToNextStep(wizard, options, state)
472481
**/
473482
function goToPreviousStep(wizard, options, state)
474483
{
475-
return paginationClick(wizard, options, state, decreaseCurrentIndexBy(state, 1));
484+
// Determine previous active step
485+
var newIndex = decreaseCurrentIndexBy(state, 1);
486+
do {
487+
if (typeof state.disabledSteps == 'undefined' || $.inArray(newIndex, state.disabledSteps) == -1) {
488+
break; //found an index that is not disabled => stop the loop
489+
}
490+
newIndex--;
491+
} while (true);
492+
493+
return paginationClick(wizard, options, state, newIndex);
476494
}
477495

478496
/**
@@ -1482,6 +1500,48 @@ $.fn.steps.setCurrentIndex = function (index)
14821500
return goToStep(this, options, state, index);
14831501
};
14841502

1503+
/**
1504+
* Disable a step so that it will be skipped on going to Next and Previous
1505+
*
1506+
* @method disableStep
1507+
* @param index {Integer} Index number of the step to disable
1508+
* @return {Boolean} Indicates whether the action executed
1509+
**/
1510+
$.fn.steps.disableStep = function (index)
1511+
{
1512+
var state = getState(this);
1513+
1514+
if (typeof state.disabledSteps == 'undefined') {
1515+
state.disabledSteps = [];
1516+
}
1517+
if ($.inArray(index, state.disabledSteps) == -1) {
1518+
state.disabledSteps.push(index);
1519+
return true;
1520+
}
1521+
return false;
1522+
};
1523+
1524+
/**
1525+
* Enable a step that was previously disabled
1526+
*
1527+
* @method enableStep
1528+
* @param index {Integer} Index number of the step to re-enable
1529+
* @return {Boolean} Indicates whether the action executed
1530+
**/
1531+
$.fn.steps.enableStep = function (index)
1532+
{
1533+
var state = getState(this);
1534+
1535+
if (typeof state.disabledSteps != 'undefined') {
1536+
var arrayIndex = $.inArray(index, state.disabledSteps);
1537+
if (arrayIndex > -1) {
1538+
state.disabledSteps.splice(arrayIndex, 1);
1539+
return true;
1540+
}
1541+
}
1542+
return false;
1543+
};
1544+
14851545
/**
14861546
* An enum represents the different content types of a step and their loading mechanisms.
14871547
*

0 commit comments

Comments
 (0)