Home

Awesome

AutoForm Wizard

AutoForm Wizard is a multi step form component for AutoForm.

Installation

$ meteor add forwarder:autoform-wizard

Upgrade notice

Upgrading to 0.7.*

Iron router support has been moved to a separate package. See the Using routers section to see how to enable it.

Dependencies

Example

A running example can be found here: http://autoform-wizard.meteor.com

The source code of the example app can be found on Github. https://github.com/forwarder/meteor-wizard-example

Basic usage

Create templates for the wizard

<template name="basicWizard">
  {{> wizard id="basic-wizard" steps=steps}}
</template>

Define the steps in a template helper

Schema = {};
Schema.information = new SimpleSchema(...);
Schema.confirm = new SimpleSchema(...);

Template.basicWizard.helpers({
  steps: function() {
    return [{
      id: 'information',
      title: 'Information',
      schema: Schema.information
    },{
      id: 'confirm',
      title: 'Confirm',
      schema: Schema.confirm,
      onSubmit: function(data, wizard) {
        // submit logic
      }
    }]
  }
});

Custom step templates

If you need more flexibility in your forms, you can define your own templates to be used for the steps.

Define your templates and include AutoForm

<template name="information">
  {{> quickform id="information-form" doc=step.data schema=step.schema}}
</template>

or

<template name="confirm">
  {{#autoForm id="confirm-form" doc=step.data schema=step.schema}}

    {{> afQuickField name="acceptTerms"}}

    {{> wizardButtons}} /* this will render back, next and confirm buttons */

  {{/autoForm}}
</template>

Configure steps

Template.basicWizard.helpers({
  steps: function() {
    return [{
      id: 'information',
      title: 'Information',
      template: 'information',
      formId: 'information-form',
    },{
      id: 'confirm',
      title: 'Confirm',
      template: 'confirm',
      formId: 'confirm-form',
      onSubmit: function(data, wizard) {
        // submit logic
      }
    }]
  }
});

Component reference

Wizard configuration

The following attributes are supported:

Custom attributes

Wizard configuration attributes can be extended with Wizard.extendOptions

  Wizard.extendOptions(['wizardClass']);

with default value:

  Wizard.extendOptions(['editButton', 'wizardClass'], {wizardClass: 'nav-wizard'});

onSubmit

Use this callback to process the form data.

onSubmit: function(data, wizard) {
  var self = this;
  Orders.insert(_.extend(wizard.mergedData(), data), function(err, id) {
    if (err) {
      self.done();
    } else {
      Router.go('viewOrder', {
        _id: id
      });
    }
  });
}

Arguments:

this references to the AutoForm instance, see the AutoForm documentation for more information.

Wizard instance methods

The wizard instance is added to your step templates data context, so you can access these methods in your event handlers etc.

Example usage:

Template.wizardStep2.events({
  'click .back': function(e, template) {
    e.preventDefault();
    this.wizard.previous();
  }
});

Using routers <a name="routers"></a>

It's possible to bind the wizard to a router. Iron Router and Flow Router are supported by default. If you're using a different router, it's easy to setup custom bindings.

Configuring a router

  1. First add the route name you want to use to your wizard instance.
{{> wizard id="order-wizard" route="order" steps=steps}}

Iron Router

First add the Wizard Iron Router package.

meteor add forwarder:autoform-wizard-iron-router

Enable the router bindings.

Wizard.useRouter('iron:router');

Add a new route to your router config, with the :step parameter.

Router.route('/order/:step', {name: 'order'});

Flow Router

First add the Wizard Flow Router package.

meteor add forwarder:autoform-wizard-flow-router

Enable the router bindings.

Wizard.useRouter('kadira:flow-router');

Add a new route to your router config, with the :step parameter.

FlowRouter.route('/order/:step', {name: 'order'});

Custom router bindings

If you use a different router you can easily setup custom bindings. This example will you show how to bind the wizard to Flow Router (meteorhacks:flow-router).

Wizard.registerRouter('kadira:flow-router', {
  go: function(name, stepId) {
    FlowRouter.go(name, this.getParams(stepId));
  },
  getParams: function(stepId) {
    var route = Router.current()
      , params = route.params || {};

    return _.extend(params, {step: stepId});
  },
  getStep: function() {
    return FlowRouter.getParam('step');
  },
  path: function(name, stepId) {
    return FlowRouter.path(name, this.getParams(stepId));
  }
});

Then to enable Flow Router add the following line to your client code.

Wizard.useRouter('kadira:flow-router');

Todo