Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There was a question close to this one on <a href="https://groups.google.com/forum/#!searchin/durandaljs/wizard/durandaljs/U6yH1Gw8Y_M/GJmZsArYz4cJ" rel="nofollow">Durandal's newsgroup</a> a while ago.</p> <p>In short instead of using router functionality use ViewModel.activator() to switch between those steps. That way you are in complete control, which steps are accessible depending on the state of your Wizard VM.</p> <p>Here's Rob's recommendation from the thread above:</p> <blockquote> <p>Compose, compose, compose. :) If I were building a wizard, here's what I would do:</p> <ol> <li>Create a module that manages the current page and transitioning next/back. Create a view for it that uses compose to bring in the current page</li> <li>Create a module for each step of the wizard, that has it's unique fields and validation.</li> <li>Create a view for each module step.</li> </ol> <p>That's all there is to it. Something like this:</p> </blockquote> <h3>Updated example:</h3> <p>Live version : <a href="http://dfiddle.github.io/dFiddle-1.2/#/view-composition/wizard" rel="nofollow">http://dfiddle.github.io/dFiddle-1.2/#/view-composition/wizard</a></p> <pre><code>define(['durandal/viewModel', './step1', './step2', './step3'], function( viewModel, Step1, Step2, Step3 ) { var steps = [new Step1(), new Step2(), new Step3()]; var step = ko.observable(0); var activeStep = viewModel.activator(); var stepsLength = steps.length; var hasPrevious = ko.computed(function() { return step() &gt; 0; }); var hasNext = ko.computed(function() { return (step() &lt; stepsLength - 1); }); // Start with first step activeStep(steps[step()]); return { showCodeUrl: true, steps: steps, step: step, activeStep: activeStep, next: next, previous: previous, hasPrevious: hasPrevious, hasNext: hasNext }; function next () { if ( step() &lt; stepsLength ) { step(step() + 1); activeStep(steps[step()]); } } function previous () { if ( step() &gt; 0 ) { step(step() - 1); activeStep(steps[step()]); } } }); </code></pre> <p>Checkout out the whole thread for more information.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload