List フィールド
行ごとにサブフォームで編集する、行の表です
list フィールドは行の表を表示し、各行は専用の サブフォーム ペインで作成、編集します (ドリルダウン方式)。7.0.0 で削除された table フィールドに代わるものです。
主な機能
list フィールドには次の機能があります。
- 各行は全画面のサブフォームで編集するため、ネストしたリストを含むすべてのフィールドの種類を使用できます。
- サブフォームは
subform型の独立したフォームであり、別々のフォームにある 複数の list フィールドで再利用 できます (たとえば、顧客、仕入先、注文などで 1 つのAddressサブフォームを共有できます)。 - マーカープロパティ (
insertMarker、updateMarker、deleteMarker) により、冪等な playbook のパターンを実現できます。 allowDelete: falseの場合、既存の行は保護されます。削除できるのは、現在のセッションで追加された行 (insertMarkerが付いた行) だけです。columnsプロパティで、サブフォームのどのフィールドを一覧表の列として表示するかを指定します。- 出力は常にオブジェクトの配列です。サブフォームのフィールドで宣言した
model、output、outputObject、valueColumnは、extravars の生成時に反映されます。
サブフォームの宣言
サブフォームは type: subform を持つ独立したフォームで、ほかのフォームと同じようにフォームフォルダー内のファイルに置きます。ほかのフォームと同じ fields 配列を受け付けますが、フォームのタイル一覧には表示されず、直接送信されることもありません。
- name: Address
type: subform
fields:
- name: street
type: text
label: Street
required: true
- name: city
type: text
label: City
required: true
- name: country
type: text
label: Country
プロパティ
list フィールドで使用できるプロパティを、用途別にまとめています。
| 属性 | 説明 |
|---|---|
| basic | |
| name string / 必須 / 一意 | Field name
This attribute represents the name of the form field. |
| type string / 必須 | Field type
Other attributes might only be available for some field types. 値: list 例Text |
| label string | Field label
A friendly name/label for the field. Note: if not set, the field name is used as label, but not when type is html. Since 6.0.3: Supports placeholders for dynamic labels (e.g., |
| help string | Field help message
Some fields require additional help information. This help message will be shown below the field. Since 6.0.3: Supports placeholders for dynamic help text (e.g., |
| subform string / 必須 | Name of the subform that defines one row
For a |
| data | |
| default many | Default value
The type of the value depends on the field type.
For |
| expression string | A javascript expression.
By default this javascript is evaluated on the server side and limited to predefined functions (for security). However in combination with tip: use the alias 例Get a list of users from a rest api Filter and sort an array of objects Make a numbered list Use the alias `local` Use the alias `local_out` |
| runLocal boolean | Run an expression locally
When running expressions, by default they are run remotely on the server. 既定値: false |
| dbConfig string, array or object | A database connection
When you want to query data from a database, you will need the proper connection information. 例get information from a mysql database (legacy example - deprecated) get information from a mysql database (new example) get information from a mysql database (array example) get information from a mongodb |
| query string | The query to select data from a database
This is typically a classic SELECT statement. Every 例get information from a mysql database get information from a mongodb |
| interaction | |
| dependencyFn string バージョン 4.0.0 で追加 | The dependency logical function
This attribute represents the logical function between multiple dependencies. 選択肢:
|
| dependencies list / elements=object | Show/hide this field based on the values or other fields
Each dependency element is either an object with the following 2 attributes:
Or with the following 2 attributes:
Use in combination with attribute 例Show a field based on a checkbox Show a field if another field is valid Show a field based on 2 fields, using the 'or' function |
| allowInsert boolean | Allow table/list insert
A table or list can be used to modify existing data. If new data is not allowed, set this property to false. 既定値: true |
| allowDelete boolean | Allow table/list delete
A table can be used to modify existing data. If you don’t was recoreds to be deleted, set this property to false. 既定値: true |
| showLoadButton boolean バージョン 6.1.5 で追加 | Show load button for file import
Enables a “Load YAML” button that allows users to import data from .yml or .yaml files. For list fields, the YAML file must contain a valid array of objects. For yaml fields, the file can contain any valid YAML structure. Single objects are automatically wrapped in arrays for list fields. 既定値: false 例List with YAML import YAML field with file import |
| showDownloadButton boolean バージョン 6.1.5 で追加 | Show download button for file export
Enables a “Download” button that exports the field content as a .yml file. The filename is automatically generated from the field name. 既定値: false |
| output | |
| output boolean バージョン 6.2.0 で追加 | Include field value as extravar
Form fields are by default sent as extravars. 既定値: true |
| model string or array | Extravar modelling
By default, a field is sent as a root-extravar. 例Model 2 fields together as a single object |
| deleteMarker string | Adds an additional deletemarker field
When you remove a record in a table, it gets removed. Since 6.4.1 the markers of a 例Mark delete record |
| insertMarker string | Adds an additional insertmarker field
When you add a record in a table, it simply gets added. 例Mark new record |
| updateMarker string バージョン 5.1.0 で追加 | Adds an additional updatemarker field
In addition to the insert and delete markers, you can also add an update marker. 例Mark updated record |
| security | |
| noLog boolean バージョン 2.2.3 で追加 | Disable backend logging
Disables logging in the backend, to hide passwords for example. 既定値: false 例hide password in log |
| validation | |
| required boolean | Required field
Makes the field required. 既定値: false |
| validIf object バージョン 2.2.4 で追加 | An field based validation (field must be true)
Enforces a validation where a referencing (expression) field must be true. This field requires an object with 2 attributes:
例Ip must be pingable |
| validIfNot object バージョン 2.2.4 で追加 | An field based validation (field must be false)
Enforces a validation where a referencing (expression) field must be false. This field requires an object with 2 attributes:
例Check if powered off |
| ignoreIncomplete boolean | Allow form submit on non-evaluated placeholders
When an expression-based field has placeholders, 既定値: false |
| visualization | |
| group string | The field group name
With this attribute you can group fields together. |
| line string バージョン 4.0.3 で追加 | The field line name
With this attribute you can group fields in a single line together. |
| width string バージョン 4.0.3 で追加 | The field width
With this attribute you can set the width of a field. 選択肢:
例Name and lastname |
| titleAdd string | Title shown in the subform pane when adding a new row
When you add a row through a |
| titleEdit string | Title shown in the subform pane when editing an existing row
When you edit a row through a |
| columns array | The list of columns visible in the dropdown/table
For an 例Show only wanted columns |
例
共有の住所サブフォーム
同じフォームの 2 つの list フィールドで、1 つの Address サブフォームを再利用します。
- name: Address
type: subform
fields:
- name: street
type: text
label: Street
required: true
- name: city
type: text
label: City
required: true
- name: country
type: text
label: Country
- name: Create customer
type: ansible
playbook: customer.yaml
roles: [default]
fields:
- name: name
type: text
label: Customer name
required: true
- name: addresses
type: list
label: Addresses
subform: Address
columns:
- city
- country
titleAdd: Add address
titleEdit: Edit address
allowInsert: true
allowDelete: true
マーカーによる追跡 (冪等性に対応)
事前に読み込まれた行は保護され、どの行が新規、変更、削除なのかをマーカーで playbook に伝えます。
- name: people
type: list
label: People
subform: Person
allowDelete: false # preloaded rows are protected
insertMarker: added # session-added rows remain removable
updateMarker: updated
deleteMarker: removed
columns:
- name
- email
行を事前に入力する
list には 3 種類のソースから事前に値を入れられます。いずれの場合も、結果の行は、参照先サブフォームのフィールド名と一致するキーを持つオブジェクトである必要があります。
静的な default
フォーム自体に記述した行です。
- name: addresses
type: list
label: Addresses
subform: Address
columns:
- city
- country
default:
- street: Main 1
city: Brussels
country: BE
- street: Side 22
city: Paris
country: FR
REST API から (expression)
サーバー側の式で REST API から読み込んだ行です。
- name: users
type: list
label: Users
subform: User
columns:
- username
- email
expression: fn.fnRestBasic('get','https://api.example.com/users','','my_api_cred','')
データベースクエリから (dbConfig + query)
データベースクエリで読み込んだ行です。
- name: servers
type: list
label: Servers
subform: Server
columns:
- hostname
- role
dbConfig: CMDB_CONN
query: SELECT hostname, role FROM servers WHERE active = 1
dbConfig は 接続 > データベース の データベース (7.5.0 から)を指定し、それ以外はこれまでどおり種類がデータベースの 認証情報を指定します( フォームでのデータベース を参照)。
ローカル式から (runLocal)
ローカル式によってブラウザーで計算した行です。
- name: ports
type: list
label: Open ports
subform: Port
columns:
- port
- protocol
runLocal: true
expression: |
[
{ port: 22, protocol: 'tcp' },
{ port: 80, protocol: 'tcp' },
{ port: 443, protocol: 'tcp' }
]
ネストしたリスト
サブフォーム自体に list フィールドを持たせて、各行の中にリストを入れられます。
- name: Address
type: subform
fields:
- name: street
type: text
label: Street
- name: city
type: text
label: City
- name: Person
type: subform
fields:
- name: name
type: text
label: Name
required: true
- name: addresses
type: list
label: Addresses
subform: Address
columns:
- street
- city
- name: My Form
type: ansible
playbook: people.yaml
roles: [default]
fields:
- name: people
type: list
label: People
subform: Person
columns:
- name
- addresses
__parent__ で親フォームのデータを参照する
サブフォームの行エディターが開くと、AnsibleForms はサブフォームに __parent__ 変数を注入します。この変数には 親フォームのすべてのフィールド値 のスナップショットが入っており、定数や vars も含まれます。
サブフォームのフィールド定義では、標準の $(...) 式の構文でこの変数を参照します。
- name: NodeConfig
type: subform
fields:
- name: node_name
type: text
label: Node name
required: true
- name: node_type
type: enum
# only offer gpu in production environments (parent field)
expression: |
'$(__parent__.environment)' === 'production'
? ['standard', 'high-memory', 'gpu']
: ['standard', 'high-memory']
runLocal: true
default: __auto__
- name: Deploy cluster
type: ansible
playbook: deploy.yml
roles: [default]
fields:
- name: environment
type: enum
values: [dev, staging, production]
required: true
- name: nodes
type: list
subform: NodeConfig
columns: [node_name, node_type]
__parent__は フロントエンド専用 のヘルパーです。Ansible の extravars からは取り除かれ、playbook に送られることはありません。