Wizard
Suddividere l’input di un modulo su più pagine con Indietro e Avanti
Che cos’è un wizard?
Un wizard trasforma un singolo modulo in una sequenza di pagine. Ogni pagina viene generata da un subform e l’utente si sposta con i pulsanti Indietro e Avanti. La convalida avviene pagina per pagina: l’utente non può andare avanti finché il passo corrente non è valido, a meno che il passo non sia contrassegnato come optional.
Alla fine di ogni wizard viene aggiunta automaticamente una pagina di riepilogo in sola lettura. Elenca ogni passo con i valori raccolti, così l’utente può confermarli prima dell’invio. La pagina di riepilogo non si dichiara in YAML; il suo titolo viene preso dalla lingua attiva.
All’invio, i valori raccolti in tutti i passi vengono uniti in un unico payload di extravars e inviati al playbook, template o workflow sottostante, esattamente come se l’utente avesse compilato un unico grande modulo.
Un modulo con un wizard non ha bisogno di fields propri, ma non può impostare enableForChat, e un subform non può avere a sua volta un wizard. La validazione all’avvio controlla l’avvio di un wizard passo per passo.
Per capire in cosa un
wizardsi differenzia da un workflow, e come si combinano, vedi la voce delle FAQ Qual è la differenza tra un wizard e un workflow?.
Proprietà a livello di modulo
Un wizard si attiva con una sola proprietà a livello di modulo:
| Attributo | Commenti |
|---|---|
| wizard array added in version 6.4.0 | Wizard steps (form-layer) Turn a form into a multi-page wizard. |
Esempi:
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 payloadProprietà dei passi del wizard
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.
| Attributo | Commenti |
|---|---|
| basic | |
| subform string / obbligatorio | Subform reference
The name of a Esempi: 1) Reference a subform |
| name string | Step namespace key
The key under which this step’s values are exposed to later steps via Esempi: 1) Override the namespace |
| title string | Page title in the stepper
Title shown in the wizard stepper and at the top of the page. Esempi: 1) Custom title |
| help string | Help text shown on this page
Help text rendered on the wizard page. Defaults to the subform’s own |
| showHelp boolean | Show help on load
When Predefinito: false |
| defaultModel string | Wrap this step's output under a prefix
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. Esempi: 1) Wrap network fields under `net` |
| workflow | |
| when expression | Conditionally show this step
When the expression evaluates falsy, the step is hidden entirely — the user never sees it and its values are not collected. Esempi: 1) Only show when kind is "vm" |
| optional boolean | Allow skipping this step
When Predefinito: false Esempi: 1) Optional advanced page |
| Esempi | |
| 1) Minimal wizard (review page is auto-added) 2) Cross-step reference and namespace prefix | |
Combinare un wizard con un workflow
Un wizard si può sovrapporre a un modulo workflow. Quando il defaultModel di ogni passo del wizard corrisponde alla extra_vars_key del nodo di workflow corrispondente, ogni playbook o template riceve solo i valori della propria pagina del wizard.
Le FAQ contengono un esempio completo e la struttura delle extravars unite: Qual è la differenza tra un wizard e un workflow? (sezione Combinati (wizard sopra un workflow)).
Un wizard su un modulo multistep, deprecato, funziona allo stesso modo, con la key del passo al posto di extra_vars_key.
Vedi anche
Pagine correlate e voci delle FAQ:
- Sottomodulo: le pagine del wizard vengono generate dai sottomoduli
- Moduli workflow: l’equivalente del wizard a livello di esecuzione
__parent__nei sottomoduli: come fare riferimento ai passi precedenti del wizard da un passo successivo