I have a simple html form with nested jQuery steps.
The Main wizard has 5 steps and the 3rd step has a sub wizard containing 3 steps.
When clicked on "Next" of main wizard, step is moved and the content is displayed but after the 3rd step (the one with sub wizard) the tab moves to the 4rth but upon reaching 4rth step no content is displayed, if I disable the jQuery script that displays the sub wizard, the main 4rth step displays content.
I tried various forums and also started debugging jQuery Steps library for a while now but couldn't find out the reason.
Any help is appreciated.
Here is the code which is also executable.
$("#frmMainWizard").steps({
headerTag: "h3",
bodyTag: "section",
transitionEffect: "slide", // "fade",
stepsOrientation: "vertical"
//enableAllSteps: true,
//enablePagination: false,
});
var childForms = $(".frmWizardSteps");
$.each(childForms, function() {
console.log(this.id);
var currentSubStesId = '#' + this.id;
$(currentSubStesId).steps({
headerTag: "h4",
bodyTag: "div",
transitionEffect: "slideLeft",
stepsOrientation: "vertical"
//autoFocus: true,
//enableAllSteps: true,
//enablePagination: false
});
});
$('#btnPrev').click(function() {
$("#frmMainWizard").steps('previous');
});
$('#btnNext').click(function() {
$("#frmMainWizard").steps('next');
});
/* Wizard styles - override jquery steps */
.wizard.clearfix > .content.clearfix {
overflow: auto !important;
}
/*
.frmMainWizard
{
border-style: solid;
border-color: blue;
border-width: 5px;
overflow:auto !important;
}
*/
/*
.frmWizardSteps
{
border-style: solid;
border-color: red;
border-width: 5px;
overflow:auto !important;
}
*/
.frmWizardSteps.wizard,
.frmWizardSteps.tabcontrol {
width: 95% !important;
}
.frmWizardSteps.wizard > .steps a,
.frmWizardSteps.wizard > .steps a:hover,
.frmWizardSteps.wizard > .steps a:active {
padding: 0.5em 0.5em !important;
}
.frmWizardSteps .content {
/*position: relative !important;*/
min-height: 20em !important;
}
.frmWizardSteps > .actions > ul {
display: inline-block;
text-align: right;
}
<link href="https://godwin.azurewebsites.net/content/jquery.steps.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://godwin.azurewebsites.net/Scripts/jquery.steps.js"></script>
<div id="frmMainWizard">
<h3>Pre prerequisites</h3>
<section>
<input id="aak_0" name="aak_0" type="checkbox" value="true" />
<label>Agent Acknowledgement</label>
<textarea class="form-control" cols="20" id="hm_0" name="hm_0" rows="5" style="min-width: 350px; width:auto;">Help material for Pre prerequisites</textarea>
<br />
<input id="sc_0" name="sc_0" type="checkbox" value="true" />
<label>Completed this step</label>
<br />
</section>
<h3>Prerequisites</h3>
<section>
<input id="aak_1" name="aak_1" type="checkbox" value="true" />
<label>Agent Acknowledgement</label>
<textarea class="form-control" cols="20" id="hm_1" name="hm_1" rows="5" style="min-width: 350px; width:auto;">Help material for prerequisites</textarea>
<br />
<input id="sc_1" name="sc_1" type="checkbox" value="true" />
<label>Completed this step</label>
<br />
</section>
<h3>Actual work</h3>
<section>
<br />
<input id="aak_2" name="aak_2" type="checkbox" value="true" />
<label>Agent Acknowledgement</label>
<textarea class="form-control" cols="20" id="hm_2" name="hm_2" rows="5" style="min-width: 350px; width:auto;">Help material for Actual work</textarea>
<br />
<br />
<div class="frmWizardSteps" id="frmWizardStep_c7514cd1-bf01-4adb-ba2a-4cd546bfc0a1">
<h4>Pre work</h4>
<div>
<br />
<br />
<textarea class="form-control" cols="20" id="hm_2_0" name="hm_2_0" rows="5" style="min-width: 350px; width:auto;">Help for Pre work</textarea>
<br />
</div>
<h4>Current work</h4>
<div>
<textarea class="form-control" cols="20" id="hm_2_1" name="hm_2_1" rows="5" style="min-width: 350px; width:auto;">Help for Current work</textarea>
<br />
</div>
<h4>Post work</h4>
<div>
<textarea class="form-control" cols="20" id="hm_2_2" name="hm_2_2" rows="5" style="min-width: 350px; width:auto;">Help for Post work</textarea>
<br />
</div>
</div>
</section>
<h3>Post actions</h3>
<section>
<input id="aak_3" name="aak_3" type="checkbox" value="true" />
<label>Agent Acknowledgement</label>
<textarea class="form-control" cols="20" id="hm_3" name="hm_3" rows="5" style="min-width: 350px; width:auto;">Help material for Post actions</textarea>
<br />
<input id="sc_2_3" name="sc_2_3" type="checkbox" value="true" />
<label>Completed this step</label>
<br />
</section>
<h3>Post post actions</h3>
<section>
<input id="aak_4" name="aak_4" type="checkbox" value="true" />
<label>Agent Acknowledgement</label>
<textarea class="form-control" cols="20" id="hm_4" name="hm_4" rows="5" style="min-width: 350px; width:auto;">Help material for Post post actions</textarea>
<br />
<input id="sc_3" name="sc_3" type="checkbox" value="true" />
<label>Completed this step</label>
<br />
</section>
</div>
<div>
<button id="btnPrev">MainPrev</button>
<button id="btnNext">MainNext</button>
</div>
Try this JSfiddle working sample that I made based on the solution suggested by @medievo in this post.
Apparently, the problem is that somehow the onStepChange
event handler for the main-wizard
is not being called anymore once sub-wizard
is initialized and displayed. I may provide additional information after debugging the library. Will keep you updated.
About the solution:
Let's say that we have two functions
that initialize main-wizard
and sub-wizard
by using jquery.steps
library.
Function for main-wizard
looks like the following:
var shoMainWizard = function(){
$("#main-wizard").steps({
/*
All your jquery.steps config stuff here
plus the following event handlers
*/
onStepChanging: function (event, currStepIndex, nextStepIndex) {
// If we are moving on the step which contains the sub-wizard (index 2)
if (nextStepIndex == 2){
shoSubWizard(currStepIndex, nextStepIndex);
}
return true;
},
onStepChanged: function (event, currStepIndex, priorStepIndex) {
$("#main-wizard-p-" + priorStepIndex).hide();
$("#main-wizard-p-" + currStepIndex).fadeIn();
}
});
};
Note that onStepChanging
handler makes the sub-wizard
to be initialized and displayed in the first call and just to be displayed in the next calls.
Note also that onStepChanged
handler toggles the view by hidding the previous-step view
and displayed the next-step view
.
Function for sub-wizard
looks like the following:
var shoSubWizard = function(currStepIndex, nextStepIndex){
// if sub-wizard note rendered yet
if (!$('#sub-wizard').hasClass('wizard')){
/*
All your jquery.steps config stuff here
plus the following event handlers
*/
onFinished: function() {
$("#main-wizard").steps("next");
}
});
}
// otherwise, display sub-wizard with last changes
else {
$("#main-wizard-p-" + currStepIndex).hide();
$("#main-wizard-p-" + nextStepIndex).fadeIn();
}
}
Note that there is an if
statement to identify whether the sub-wizard
was already initialized or not by asking if it already has wizard
class that jquery.steps
adds. In case it was already initialized, we just need to show()
it.
Note also that the onFinished
handler makes the main-wizard
to continue with the next-step
.
Hope this helps to solve your problem.
EDIT:
After reviewing and debugging the code, the problem is that following jQuery
query (line #1196 from library) gets all steps content
from main-wizard
and sub-wizard
and makes the transition (from the step which contains the sub-wizard to the next step) to be messed up among them.
var stepContents = wizard.find(".content > .body")
Changing that line by the following one fixes the issue. However, there are some other lines that need similar fix.
var stepContents = wizard.find("> .content > .body")
Note also that there is a pull request pending to approve that apparently fixes the issue. However, IMHO, that pull request changes directly the built file from the library, and it probably won't get approved.
EDIT 2:
Pull request created here to fix the issue about having nested jquery.steps wizards.