Wizard

Die Eingaben eines Formulars mit Zurück und Weiter auf Seiten verteilen



Was ist ein Wizard?

Ein Wizard macht aus einem einzelnen Formular eine Folge von Seiten. Jede Seite wird aus einem subform dargestellt, und der Benutzer navigiert mit den Schaltflächen Zurück und Weiter. Die Validierung gilt pro Seite: Der Benutzer kann erst weitergehen, wenn der aktuelle Schritt gültig ist, es sei denn, der Schritt ist als optional markiert.

Am Ende jedes Wizards wird automatisch eine schreibgeschützte Übersichtsseite angehängt. Sie listet jeden Schritt mit den gesammelten Werten auf, damit der Benutzer sie vor dem Absenden bestätigen kann. Die Übersichtsseite wird nicht in YAML deklariert; ihr Titel stammt aus der aktiven Sprache.

Beim Absenden werden die gesammelten Werte aller Schritte zu einer einzigen Extravars-Payload zusammengeführt und an das zugrunde liegende Playbook, die Vorlage oder den Workflow gesendet, genau so, als hätte der Benutzer ein einziges großes Formular ausgefüllt.

Ein Formular mit wizard braucht keine eigenen fields, kann aber enableForChat nicht setzen, und ein subform kann selbst keinen wizard haben. Die Start-Validierung prüft den Start eines Wizards Schritt für Schritt.

Wie sich ein wizard von einem Workflow unterscheidet und wie sich beide kombinieren lassen, steht im FAQ-Eintrag Was ist der Unterschied zwischen einem Wizard und einem Workflow?.


Eigenschaft auf Formularebene

Ein Wizard wird mit einer einzigen Eigenschaft auf Formularebene aktiviert:

Attribut Kommentare
wizard
array
hinzugefügt in Version 6.4.0

Wizard steps (form-layer)

Turn a form into a multi-page wizard.
Where steps splits the execution into multiple jobs, wizard splits the input of a single form into multiple pages.
Each wizard step references a subform and is rendered as its own page with Back / Next navigation. A read-only review page is appended automatically as the last step — you do not declare it in YAML.
See the Wizard page for all step properties and examples.

Beispiele:

1) Three-step wizard

name: Provision host
type: ansible
roles:
  - default
playbook: provision.yml
wizard:
  - subform: basics
    title: Basics
  - subform: network
    title: Network
    defaultModel: net
  - subform: advanced
    title: Advanced
    optional: true
    when: $(__parent__.basics.kind) === 'vm'

2) Wizard mapped one-to-one onto multistep (defaultModel + key)

name: Provision and verify host
type: multistep
roles:
  - default
wizard:
  - subform: basics
    title: Basics
    defaultModel: basics      # wraps fields under `basics`
  - subform: network
    title: Network
    defaultModel: network     # wraps fields under `network`
steps:
  - name: Create host
    type: ansible
    playbook: create_host.yml
    key: basics                # receives only the basics payload
  - name: Configure network
    type: ansible
    playbook: configure_network.yml
    key: network                # receives only the network payload

Eigenschaften der Wizard-Schritte

Each wizard step references a subform and is rendered as its own page with Back and Next navigation. The user must validate one step before moving to the next; data from earlier steps is available in later steps via __parent__.

Review step is automatic. A read-only summary page that lists every step’s input is appended as the last page of the wizard. You do not declare it in YAML — its title is taken from the active locale (“Summary” / “Samenvatting” / “Zusammenfassung” / …).

Wizard vs Multistep. steps splits the execution into multiple sequential jobs (each step is its own playbook/template). wizard splits the input of a single form into multiple pages — only one job runs at the end. The two can be combined: a type: multistep form can also have a wizard: block to gather its extravars across pages.

Attribut Kommentare
basic
subform
string / erforderlich

Subform reference
a valid subform name

The name of a type: subform form to render on this wizard page. The subform’s fields become this step’s inputs.

Beispiele:

1) Reference a subform

wizard:
  - subform: basics
  - subform: network
name
string

Step namespace key
alphanumeric + dash + underscore

The key under which this step’s values are exposed to later steps via $(__parent__.<name>.<field>).
Defaults to the value of subform when omitted.
Set this explicitly when you reuse the same subform multiple times in the same wizard, or when you want a stable key independent of the subform name.

Beispiele:

1) Override the namespace

wizard:
  - subform: address
    name: shipping
  - subform: address
    name: billing
title
string

Page title in the stepper
free text

Title shown in the wizard stepper and at the top of the page.
Defaults to the subform’s description, or to the step’s name if no description is set.

Beispiele:

1) Custom title

wizard:
  - subform: basics
    title: Tell us about your host
help
string

Help text shown on this page
free text (markdown supported)

Help text rendered on the wizard page. Defaults to the subform’s own help when omitted.

showHelp
boolean

Show help on load
true, false

When true, the help block is expanded by default when the user lands on this page. Falls back to the subform’s showHelp when omitted.

Standard:
false
defaultModel
string

Wrap this step's output under a prefix
a model path (dot notation allowed)

Wraps every field of this step under the given object key in the final extravars payload. Useful when you reuse a generic subform and want its values namespaced.
Without defaultModel, fields are merged into the top level of the extravars (still grouped per step under __parent__ for cross-step references).

Beispiele:

1) Wrap network fields under `net`

wizard:
  - subform: network
    defaultModel: net

# The subform has fields `hostname` and `ipv4`.
# Final extravars contain:
#   net:
#     hostname: ...
#     ipv4: ...
workflow
when
expression

Conditionally show this step
a JavaScript expression returning truthy/falsy

When the expression evaluates falsy, the step is hidden entirely — the user never sees it and its values are not collected.
The expression has access to all earlier steps via __parent__.<stepname>.<field>. Steps after a hidden one are renumbered automatically.
Note: when is purely about visibility; it is unrelated to optional, which is about whether the user is allowed to skip a visible step.

Beispiele:

1) Only show when kind is "vm"

wizard:
  - subform: basics       # has a `kind` enum field
  - subform: advanced
    when: $(__parent__.basics.kind) === 'vm'
optional
boolean

Allow skipping this step
true, false

When true, the user can press Next even if the step’s fields are not (yet) valid, and Submit is allowed without ever visiting this step.
The step is still shown in the stepper — use when if you want to hide it altogether.

Standard:
false

Beispiele:

1) Optional advanced page

wizard:
  - subform: basics
  - subform: advanced
    optional: true
Beispiele

1) Minimal wizard (review page is auto-added)

- name: Provision host
  type: ansible
  roles:
    - default
  playbook: provision.yml
  wizard:
    - subform: basics
    - subform: network

- name: basics
  type: subform
  fields:
    - name: hostname
      type: text
      required: true

- name: network
  type: subform
  fields:
    - name: ipv4
      type: text

2) Cross-step reference and namespace prefix

wizard:
  - subform: basics
    title: Basics
  - subform: network
    title: Network
    defaultModel: net          # wraps network fields under `net`

# In the `network` subform you can reference fields
# from the `basics` step like this:
#   default: $(__parent__.basics.hostname).local

Einen Wizard mit einem Workflow kombinieren

Ein Wizard lässt sich auf ein Workflow-Formular aufsetzen. Wenn das defaultModel jedes Wizard-Schritts zum extra_vars_key des entsprechenden Workflow-Knotens passt, erhält jedes Playbook und jede Vorlage nur die Werte der eigenen Wizard-Seite.

Die FAQ enthält ein ausgearbeitetes Beispiel und den Aufbau der zusammengeführten Extravars: Was ist der Unterschied zwischen einem Wizard und einem Workflow? (Abschnitt Kombiniert (Wizard auf einem Workflow)).

Ein Wizard auf einem veralteten multistep-Formular funktioniert genauso, mit dem key des Schritts statt extra_vars_key.


Siehe auch

Verwandte Seiten und FAQ-Einträge: