Campo Enum

Un desplegable con búsqueda, para una o varias opciones


Propiedades

Las propiedades disponibles para un campo enum, agrupadas por finalidad:

Atributo Comentarios
basic
name
string / obligatorio / único

Field name
Alfanumeric + underscore + dash

This attribute represents the name of the form field.

type
string / obligatorio

Field type

Other attributes might only be available for some field types.

Valor:
enum
label
string

Field label
Free text

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., Label: $(fieldname)).

placeholder
string

In-field help value
Free text

Some form fields allow an in-field hint value.

Since 6.0.3: Supports placeholders for dynamic hints (e.g., Enter password (min $(minLength) chars)).

help
string

Field help message
Free text

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., This field depends on $(fieldname)).

data
values
array

A list of values

To manually populate an enum field

default
many

Default value

The type of the value depends on the field type.
Can be string,boolean, number, array or object. When using multiple, the default must be an array.
When using an enum field, you can use the following special values:

  • __auto__: select the first
  • __none__: select none
  • __all__: select all (if multiple is true)

For yaml fields, the default can be any valid YAML structure (object or array). For list fields, the default must be an array of objects matching the referenced subform’s fields. Use it to pre-populate the list with existing rows on form load.

evalDefault
boolean
añadido en la versión 4.0.5

Evaluates default value

A default can be treated as javascript and can thus hold expressions like '$(other_field)'.toUpperCase() or Math.PI or new Date().toISOString()

Por defecto:
false
expression
string

A javascript expression.
Valid javascript

By default this javascript is evaluated on the server side and limited to predefined functions (for security). However in combination with runLocal, the evaluation is ran in the browsers sandbox and allows the full javascript power. An html field always evaluates its expression in the browser, as with runLocal: true: it never runs on the server. When used in an enum field, the expression must return a flat array or array of flat objects, to make it presentable in a dropdown box.
An expression supports placeholders: $(fieldname) is replaced by the value of that field before the expression runs.
On the server, the predefined functions are called as fn.<name>(...), for example fn.fnTime().

tip: use the alias local (type=’expression’,runLocal=true,hide=true,output=false)
tip: use the alias local_out (type=’expression’,runLocal=true,hide=true)
tip: use the alias credential (type=’expression’,runLocal=true,hide=true,asCredential=true)

runLocal
boolean

Run an expression locally

When running expressions, by default they are run remotely on the server.
But remote expressions are limited to predefined functions.
To unleash more javascript power, use this property.
The code will be evaluated in the sandbox of the browser, offloading the server, saving api-calls and making it more secure.

Por defecto:
false
refresh
boolean|string

Allow a manual or auto refresh

A query or expression is by default run once (if it doesn’t contain any dependencies).
Sometimes a refresh would be handy.
Set this property to true to allow a refresh, or set 5s for example to allow auto refresh.

Por defecto:
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.
Name a database of Connections > Databases : it connects with the credential of type database it names (the database type, server, database and login).
Since 7.5.0 : a name that is no database is looked up as a credential of type database, as older forms do, so they keep working unchanged.
Legacy was to pass an object (name and type) ; it still works, its name a database or a credential.
Since version 5.0.2 you can just specify the name. The type is fetched from the credential (mysql, mssql, postgres, oracle or mongodb). In case of no type set, mysql is assumed.
Additionally you can set an array of names, to use multiple databases with a single query. The result will be a join of the results.
Doubles will not be removed automatically.

query
string

The query to select data from a database
A valid sql query

This is typically a classic SELECT statement.
However, in the case of mongodb, the query is slightly different. See the examples.
A query supports placeholders: $(fieldname) is replaced by the value of that field before the query runs.

Every $(...) value is escaped for the database engine before it is pasted into the query: single quotes are doubled, backslashes are doubled too on mysql (postgres, mssql and oracle keep them as they are), and on mongodb the value is escaped as the body of a JSON string. An object or array value is pasted as json, escaped the same way.
This protects a quoted placeholder (where name='$(name)') only: an unquoted one (limit $(n)) is pasted as plain text, so quote your placeholders.

jq
string
añadido en la versión 6.1.4

Transform database query results with jq
A valid jq expression

Apply a jq expression to transform the result of a query (with dbConfig).
jq is a post-processor applied server-side, after the query returns, to filter, map or reshape the result.
It only applies to query results: on an expression, server-side or local (runLocal: true), jq is ignored.

multiple
boolean

Allow multiple selection

When you want to select multiple items from a dropdown box, set this property to true. The field’s value is then a list of the selected items.

Por defecto:
false
childrenColumn
string
añadido en la versión 7.9.0

Show the rows as a tree that folds open

The key in a row that holds its child rows, an array of rows. The rows of the enum become a tree: a row with children gets a caret, and a click on the caret folds it open or closed. Children can have children of their own, under the same key, as deep as the data goes.
With one column the field looks like a tree; with several columns, like a table whose rows fold open. The columns are those of all rows on every level (a child may have columns its parent lacks), without the children’s key; columns still picks and orders them.
The rows start folded. While you type in the search box, the rows that match are shown, with the rows above them unfolded. A column header sorts each level on its own, the children staying under their parent.
A selected row is sent as it is, children included; use valueColumn or model to send only part of it. Use selectableLevels to choose which levels can be selected.
Not used with horizontal.

valueColumn
string

The column of a selected item that needs to exported as extravar

When you select an item in an enum field, by default the first column is used to send as extravar.
By setting this property, you can change it to another field.
This setting is ignored when outputObject is true.

new in v4.0.20: setting valueColumn to “*” will export all columns

Por defecto:
first column
placeholderColumn
string

The column of a selected item that is used in a placeholder

When you select an item in an enum field and later on you use this field as a placeholder, by default the first column is used as a value.
By setting this property you change the column to be used.
NOTE: this property is somewhat out-of-date since the introduction of the dot-notation.
See examples below.

New in v4.0.20: setting placeholderColumn to “*” will output the entire record, instead of a single column.

Por defecto:
first column
interaction
dependencyFn
string
añadido en la versión 4.0.0

The dependency logical function

This attribute represents the logical function between multiple dependencies.

Opciones:
  • and (por defecto)
  • or
  • nand
  • nor
dependencies
list / elements=object

Show/hide this field based on the values or other fields
Reference to other formfields and their values

Each dependency element is either an object with the following 2 attributes:

  • name: holds the fieldname.
  • values: a list of valid values for the referenced field.

Or with the following 2 attributes:

  • name: holds the fieldname.
  • isValid: a boolean to check if the referenced is validated or not.

Use in combination with attribute dependencyFn.

filterColumns
array

The list of columns that you can filter on

By default the previewColumn or first visible column is used to filter on.
With this property you can filter on the columns you want.

sortable
boolean
añadido en la versión 7.9.0

Sort the table by clicking a column header

An enum with columns shows a table. A click on a column’s header sorts its rows A to Z (0 to 9), a second click Z to A, and a third shows them again in the order the expression or query returned. Numbers sort as numbers, text as it reads (kvm-9 before kvm-10), and empty cells always go last.
The sort is only how the rows are shown: what is selected, and the value sent to the job, do not change. The search box still filters, and its rows are sorted the same way.
Set it to false to keep the rows in the order they came in.

Por defecto:
true
selectableLevels
array
añadido en la versión 7.9.0

Which levels of a tree can be selected

With childrenColumn, the levels of the tree that can be selected: 0 is the top level, 1 the children, 2 their children, and so on. A row on another level is shown in a muted colour, and a click on it only folds it open or closed.
Selecting a row never selects its children. When several levels can be selected, the value can hold rows of different levels.
With multiple, a row on a level that cannot be selected gets a box of its own when there are rows below it that can: it selects them all (or, when they all are, none), and shows whether all, some or none of them are selected. While you search, it acts on the rows that match. The row itself is never part of the value. The box in the header acts on all the rows that can be selected, folded open or not.

Por defecto:
[0]
detailView
string
añadido en la versión 7.9.0

Show the details of a row

Shows the details of a row, with more than its columns show (master/detail):

  • none: no details
  • row: each row gets an info icon at its end; a click on it opens the row’s details under the row, a second click closes them. A click on the row itself still selects it.
  • split: the rows on the left, the details of the row clicked last on the right. Only for a sticky enum: a dropdown has no room for it and shows the details as with row.

The details are the detailTemplate filled from the row, or, without one, the row on its side: each column with its value (detailColumns, all by default). A column holding a list of objects shows as a small table, another object or list as JSON.
Works with childrenColumn: every row, on every level, has its details.

Por defecto:
none
detailTemplate
string
añadido en la versión 7.9.0

The details of a row, as markdown

With detailView, the details of a row as markdown (html inside it allowed). Placeholders $(column) are filled from the row; a path goes deeper, $(owner.name) or $(jobs[0].name), and $(.) is the row itself when it is not an object. An object or a list is filled in as JSON.
The values of the row are encoded and the result is sanitized: data never becomes html, and the template only keeps what is safe (no scripts, no event handlers).

detailColumns
array
añadido en la versión 7.9.0

The columns the details of a row show

With detailView and no detailTemplate, the columns the details show, in this order: the row on its side, each column with its value. All the row’s columns by default.

output
output
boolean
añadido en la versión 6.2.0

Include field value as extravar

Form fields are by default sent as extravars.
Set to false to exclude a field from the extravar output.

Por defecto:
true
model
string or array

Extravar modelling
An dot-based string notation of an object, or an array of these

By default, a field is sent as a root-extravar.
If you want model the output of the extravars, you can specify a dot-notation of how this field should be modelled.

asCredential
boolean

Send credential as extravar

Use the value of this field to search for a credential with the same name
and send that credential (with user and password) hidden to the playbook as extravar.

Since 4.0.16, you can use this in combination with the credentials form-property.

Por defecto:
false
outputObject
boolean

Output the selection of a enum-field as a full object.

When selecting from an enum-field (dropdown), either the first column or
the column defined in valueColumn is sent as an extravar.
If you want the full selected record, use the property.

New in v4.0.20: valueColumn: “*” has the same behavior, and will output all columns

Por defecto:
false
security
noLog
boolean
añadido en la versión 2.2.3

Disable backend logging

Disables logging in the backend, to hide passwords for example.

Por defecto:
false
validation
required
boolean

Required field

Makes the field required.

Por defecto:
false
validIf
object
añadido en la versión 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:

  • field: The name of the referencing field
  • description: A validation message to show when the validation is not met. (Since 5.0.1: Supports placeholders for dynamic messages)

validIfNot
object
añadido en la versión 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:

  • field: The name of the referencing field
  • description: A validation message to show when the validation is not met. (Since 5.0.1: Supports placeholders for dynamic messages)

ignoreIncomplete
boolean

Allow form submit on non-evaluated placeholders

When an expression-based field has placeholders,
the default form behaviour is not to allow form submit until all placeholders are resolved. When this attribute is true, the form does not wait for placeholder completion for this field.

Por defecto:
false
visualization
icon
string

Field icon
Free fontawesome 6 icon

Some formfields can hold a nice looking icon. The icon name is a free fontawesome 6 icon. You can find more information at www.fontawesome.com

group
string

The field group name
Free text

With this attribute you can group fields together.
When all fields in a group are hidden (due to dependencies), the group is also hidden.

line
string
añadido en la versión 4.0.3

The field line name
Free text

With this attribute you can group fields in a single line together.
Use together with the width parameter to set the width, if not, the width is auto.

width
string
añadido en la versión 4.0.3

The field width
A valid Bootstrap Column width

With this attribute you can set the width of a field.
Use together wit the line parameter to put fields on 1 line. see https://getbootstrap.com/

Opciones:
  • col-1
  • col-2
  • col-3
  • col-4
  • col-5
  • col-6
  • col-7
  • col-8
  • col-9
  • col-10
  • col-11
  • col-12
sticky
boolean

Make a dropdown box permanently visible

A enum field is by default a dropdown box. However, you can change that behavior by setting this property.
The dropbox looses it reactivity and becomes a fixed table.

Por defecto:
false
horizontal
boolean
añadido en la versión 4.0.3

Converts a dropdown box to a horizontal selector

A enum field is by default a dropdown box. However, you can change that behavior by setting this property.
The unselected values are on the left and the selected values on the right. This works in combiniation with sticky.
PctColumns are disabled, due to the space it consumes horizontally.

Por defecto:
false
columns
array

The list of columns visible in the dropdown/table

For an enum field: all properties are shown by default. Use this property to choose which columns are visible in the dropdown.
For a list field: all scalar subform fields are shown by default. Use this property to pick which subform fields render as columns in the list table (missing names soft-fail and render as empty columns).

pctColumns
array

The list of columns that should visualized as a percentage-bar

By default all properties are show with its regular value.
With a percentage it can be nice to visualize it as a graphical bar.
The assumption is that the value is an integer between 0 and 100.

previewColumn
string

The column of the selected item(s) that is shown in the dropdown-preview

When you select an item in an enum field, by default the first column is used as a preview.
By setting this property you change the column to be used.

Por defecto:
first column

Árboles

Las filas pueden contener sus propias filas: un grupo con sus jobs, un centro de datos con sus clústeres y sus hosts. Indique la clave que las contiene en childrenColumn y el enum muestra un árbol desplegable, tan profundo como lleguen los datos. Con una columna parece un árbol, con varias una tabla cuyas filas se despliegan.

- name: groups
  type: enum
  sticky: true
  multiple: true
  childrenColumn: jobs
  columns: [name, description, owner]
  valueColumn: name
  values:
  - name: nightly
    description: Nightly jobs
    jobs:
    - { name: backup-db, description: Back up the databases, owner: dba }
    - { name: rotate-logs, description: Rotate the logs, owner: ops }
  - name: weekly
    description: Weekly jobs
    jobs:
    - { name: patch, description: Patch the servers, owner: ops }
  • Una flecha despliega o pliega una fila; las filas empiezan plegadas.
  • Las columnas son las de las filas de todos los niveles: un job puede mostrar una columna que su grupo no tiene. columns sigue eligiéndolas y ordenándolas.
  • Escribir en el cuadro de búsqueda muestra las filas que coinciden, con las filas superiores desplegadas.
  • Una cabecera de columna ordena cada nivel por separado; los hijos permanecen bajo su padre.
  • Una fila seleccionada se envía tal cual, con sus hijos. Use valueColumn o model para enviar solo una parte.

Las filas suelen venir de una expresión o una consulta, jq puede darles forma, siempre que cada fila guarde sus hijos bajo la misma clave.

Qué niveles se pueden seleccionar

selectableLevels enumera los niveles que un usuario puede seleccionar: 0 es el nivel superior, 1 sus hijos, 2 los de estos. Por defecto es [0]. Una fila de otro nivel aparece atenuada, y un clic en ella solo la despliega o la pliega.

- name: jobs
  type: enum
  sticky: true
  multiple: true
  childrenColumn: jobs
  selectableLevels: [1]
  columns: [name, description]
  valueColumn: name
  expression: "fn.fnReadJsonFile('/app/dist/persistent/jobgroups.json')"

Con multiple, una fila que no se puede seleccionar recibe su propia casilla cuando debajo hay filas que sí se pueden: las selecciona todas, o ninguna cuando ya lo están todas, y muestra si están seleccionadas todas, algunas o ninguna. Arriba, un clic en la casilla de nightly selecciona todos sus jobs; el valor contiene los jobs, nunca el grupo. La casilla de la cabecera selecciona todas las filas seleccionables, desplegadas o no.

Seleccionar una fila nunca selecciona sus hijos. Cuando se pueden seleccionar varios niveles ([0, 1]), el valor puede contener filas de distintos niveles.


Detalles

Una fila puede mostrar más que sus columnas. detailView indica dónde:

  • row: cada fila recibe un icono de información al final, y un clic en él abre los detalles de la fila debajo de ella.
  • split: las filas a la izquierda, los detalles de la última fila pulsada a la derecha. Para un enum sticky; una lista desplegable los muestra como con row.

Sin nada más, los detalles son la fila tumbada: cada columna con su valor. Una columna con una lista de objetos se muestra como una pequeña tabla, así un grupo muestra sus jobs. detailColumns elige y ordena las columnas.

- name: groups
  type: enum
  sticky: true
  columns: [name]
  valueColumn: name
  detailView: split
  detailColumns: [description, jobs]
  values: ...

Una plantilla

detailTemplate escribe los detalles en markdown, con html permitido. $(column) se rellena desde la fila; una ruta va más hondo, $(owner.name) o $(disks[0].dev), y $(.) es la propia fila cuando no es un objeto.

- name: servers
  type: enum
  sticky: true
  columns: [name, os]
  valueColumn: name
  detailView: split
  detailTemplate: |
    ### $(name)
    **OS**: $(os) - **owner**: $(owner.name)

    | disk | GB |
    |---|---|
    | $(disks[0].dev) | $(disks[0].gb) |

    _$(notes)_
  expression: "fn.fnReadJsonFile('/app/dist/persistent/servers.json')"

Los valores de la fila se codifican y el resultado se sanea: los datos nunca se convierten en html, y la plantilla solo conserva lo seguro, sin scripts ni manejadores de eventos.

Árboles y detalles van juntos: con childrenColumn y detailView, cada fila, en cada nivel, tiene sus detalles.


Ejemplos

Ejemplos de campos enum, en YAML:

Queries

La definición del campo, en YAML:

since queries are so diverse, there is a separate section on queries with examples.