向导
用“返回”和“下一步”把表单输入拆分到多个页面
什么是向导?
向导把单个表单变成一系列页面。每个页面都由一个 subform 渲染,用户通过返回和下一步按钮浏览。校验按页面执行:在当前步骤有效之前,用户无法继续前进,除非该步骤标记为 optional 。
每个向导的末尾都会自动追加一个只读的审阅页面。它列出每个步骤及其收集到的值,方便用户在提交前确认。审阅页面不在 YAML 中声明;其标题取自当前使用的语言。
提交时,所有步骤收集到的值会合并成一份 extravars,发送给底层的 playbook、模板或工作流,效果与用户填写了一个大表单完全相同。
带有 wizard 的表单不需要自己的 fields ,但不能设置 enableForChat ,而且 subform 本身不能有 wizard 。运行验证会逐个步骤检查向导的运行。
关于
wizard与工作流有何不同,以及二者如何结合,请参阅常见问题条目向导和工作流有什么区别?。
表单级属性
向导通过一个表单级属性启用:
| 属性 | 说明 |
|---|---|
| wizard array 在版本 6.4.0 中添加 | Wizard steps (form-layer) Turn a form into a multi-page wizard. |
示例:
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向导步骤属性
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.
| 属性 | 说明 |
|---|---|
| basic | |
| subform string / 必填 | Subform reference
The name of a 示例: 1) Reference a subform |
| name string | Step namespace key
The key under which this step’s values are exposed to later steps via 示例: 1) Override the namespace |
| title string | Page title in the stepper
Title shown in the wizard stepper and at the top of the page. 示例: 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 默认值: 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. 示例: 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. 示例: 1) Only show when kind is "vm" |
| optional boolean | Allow skipping this step
When 默认值: false 示例: 1) Optional advanced page |
| 示例 | |
| 1) Minimal wizard (review page is auto-added) 2) Cross-step reference and namespace prefix | |
将向导与工作流结合
向导可以叠加在工作流表单之上。当每个向导步骤的 defaultModel 与对应工作流节点的 extra_vars_key 一致时,每个 playbook 或模板只会收到来自其对应向导页面的值。
常见问题中有一个完整示例,以及合并后 extravars 的结构:向导和工作流有什么区别?( 组合使用(在工作流之上叠加向导) 一节)。
在已弃用的 multistep 表单上使用向导也是同样的方式,只是用步骤的 key 代替 extra_vars_key 。
另请参阅
相关页面和常见问题条目:
- 子表单:向导页面由子表单渲染
- 工作流表单:在执行层面与向导相对应的功能
- 子表单中的
__parent__:如何在后面的步骤中引用前面的向导步骤