I came across function in jquery.steps.js
library :
/**
* Routes to a specific step by a given index.
*
* @static
* @private
* @method goToStep
* @param wizard {Object} The jQuery wizard object
* @param options {Object} Settings of the current wizard
* @param state {Object} The state container of the current wizard
* @param index {Integer} The position (zero-based) to route to
* @return {Boolean} Indicates whether the action succeeded or failed
**/
function goToStep(wizard, options, state, index)
{
if (index < 0 || index >= state.stepCount)
{
throwError(_indexOutOfRangeErrorMessage);
}
if (options.forceMoveForward && index < state.currentIndex)
{
return;
}
var oldIndex = state.currentIndex;
if (wizard.triggerHandler("stepChanging", [state.currentIndex, index]))
{
// Save new state
state.currentIndex = index;
saveCurrentStateToCookie(wizard, options, state);
// Change visualisation
refreshStepNavigation(wizard, options, state, oldIndex);
refreshPagination(wizard, options, state);
loadAsyncContent(wizard, options, state);
startTransitionEffect(wizard, options, state, index, oldIndex);
wizard.triggerHandler("stepChanged", [index, oldIndex]);
}
else
{
wizard.find(".steps li").eq(oldIndex).addClass("error");
}
return true;
}
I would like to use this function so every time user submit a form on step 3
in the wizzard he would not be redirected again to step 1
but to stay at step 3
.
Bellow is mine script:
$("#wizard-2").steps({
headerTag: "h3",
bodyTag: "section",
transitionEffect: "slideLeft",
onStepChanging: function (event, currentIndex, newIndex)
{
$("#form-2").validate().settings.ignore = ":disabled,:hidden";
return $("#form-2").valid();
},
onFinishing: function (event, currentIndex)
{
$("#form-2").validate().settings.ignore = ":disabled";
return $("#form-2").valid();
},
onFinished: function (event, currentIndex)
{
$('<input />').attr('type', 'hidden')
.attr('name','ssl')
.attr('value', 'true')
.appendTo('#form-2');
document.getElementById("form-2").submit();
}
});
<? if ($_POST['submit'])
echo "$(\"wizard-2\").goToStep(this, ,3,0);"?>
But I believe my execution of this function is pretty bad cause it ain't work. Could anyone help me out with this script?
I figured out it myself. Problem was pretty easy and it was about setting correctly attribute startIndex
like:
<?
if (Env::value('generate'))
echo "startIndex: \"2\",";
?>