I need to create a wizard with multiple steps. Each step will display a form with options, and depending on the user choices, the wizard should go to a certain step, as well as keeping user preferences (choices) stored in some place.
These preferences are not saved in the model, they are only relevant to the step of model creation.
In order to give some context, the goal of this is:
- Make the user a few questions regarding the opening hours of his business. For example: Is it open on weekends?, Is it different in summer?.
- According to the answers to these questions, a final form will be displayed to create the timetable(s) model(s).
The question is, which would be the best way to accomplish this inside Ember?
Here are my –Ember newbie– thoughts:
- Create a template for each wizard step.
- Keep track of the current step. Where? Controller? Route?
- Display these templates into
outlets
, which should be rendered dynamically according to the current step. This is where I get completely lost. How to do this? Should each step have a different route or not? - Keep track of user answers in the controller.
- Once the wizard is finished, load the form template, which will read user preferences stored in controller.
Versions being used:
- Ember.VERSION : 1.0.0-rc.1 application.js:9268
- Handlebars.VERSION : 1.0.0-rc.3 application.js:9268
- jQuery.VERSION : 1.9.1
Answering an old question in case someone needs some answers.
You can use something like this Multi-step form (or multiple "pages") in one route using Ember.js
this utilizes 1 route and each step/page is shown or hidden using {{#if}} To answer Nino's question, when I implemented this I had an object in my controller keeping track of all the values of the form fields and updating it as I click on next. When you get to the last page where you submit, you can simply plug this object into your controller's submit function like this
Good for simple implementation of a multi-page form. Problem I have with this is I have jQuery UI code that hooks into the view's didInsertElement and it works just that when I go from one step to another and come back (each page has 'next' and 'prev' buttons), I find that whatever the code that was ran at didInsertElement becomes undone. It's like the chunk of html code wasn't just hidden and re-shown. It was reloaded and thus all effects are gone.
I know this an old thread and probably won't help the OP, but stackoverflow leads to more answers than anything else. I just wrote a blog post on this.
Look at this JSBin to see what I've done. I'll summarize here.
Route per step in template:
Custom computed property that changes values when the routes change (in this case when the steps of the wizard changes)
A
route-value
object:A controller mixin for being aware of the current route:
The resource controller:
Think of the route value object as meaning, "When the route equals routeVal.route, the following properties will have these values" eg "When the currently active route is 'wizard.index' the next transition is to 'wizard.review', the next button text is 'Review', the previous button should be hidden, etc"
And lastly, your resource template:
You can look at the jsbin for what the form-wizard component was (just a wrapping around the css for Fuelux wizards that keeps the active class on the correct step based on the route). The body of the wizard is the template for each of the subroutes. The next/prev button's text change depending on the route, as do their transitions (since the transition depends on the current state of the wizard). It's more or less a FSM
Sounds like you are on the right track.
Yes, that is a good start.
Either controller or route would work. Route makes most sense if you want bookmarkable urls for each step and for back/forward to work and is probably the most straightforward solution. Will assume you've chosen route.
Since each step will be a route, ember will take care of rendering appropriate template automagically.
Think of "finished" as just another step. Each step gets it's own controller which is used to record user responses. The last controller uses "needs" to access earlier controllers in order to customize behavior based on responses to the wizard.