Fields
In a form, the field is the basic unit of data entry and the only thing that will be stored is database.
The fields are declared in the database and referenced in the screen with the FieldRef
object.
To create a valid FieldRef
object, you need to understand the structure and elements of the FieldRef
class. Below is a detailed documentation of each element of the FieldRef
object.
FieldRef
Object
A FieldRef
object represents a reference to a field in the form and contains various elements such as metadata, default values, validators, and more.
JSON Example
{
"metadata": {
"key": "value"
},
"default": "default value",
"calculated_default_value": "lua function to set default value",
"calculated_value": "lua function",
"on_change": "lua function",
"slug": "field-slug",
"name": "Reference for Layout, use slug instead",
"label": "Display name for field"
}
Elements of FieldRef
metadata
Use metadata to specify data, for example you can set the product uuid you are working with as
"product_uuid": "MY_PRODUCT_UUID"
If the metadata is set to null
, the value will be setted automatically by dispatchers.
- Type: Map<String, dynamic>
- Mandatory: true
- Description: Metadata associated with the field. Used to distinguish between fields with the same name
Example:
"metadata": {
"key": "value"
}
default
- Type: dynamic
- Description: The default value of the field. Must be the same type as the field.
Example:
"default": "default value"
calculated_default_value
- Type: String
- Description: The default value calculated by a Lua function.
Example:
"calculated_default_value": "lua function"
calculated_value
- Type: String
- Description: The value calculated by a Lua function.
Example:
"calculated_value": "lua function"
history
- Type: Boolean
- Default: false
- Description: If the field is loaded from the previous form.
Example:
"history": true
evolution
- Type: Boolean
- Default: true
- Description: If the field compares the value with the previous form.
Example:
"evolution": false
on_change
- Type: String
- Description: Lua function called whenever the value of the field changes. The return value of the function is the new value of the field. The value can be acceced with
_S.fieldValue
.
Example:
"on_change": "lua function"
hidden
- Type: Boolean
- Description: If the field is hidden but still calculated. Used to store value in the database without displaying it to the user.
Example:
"hidden": false
slug
- Type: String
- Mandatory: true
- Description: The slug of the field. Used to reference the field in the screen and in database.
Example:
"slug": "field-slug"
name
- Type: String
- Description: The name of the field. Used to reference the field in the layout, usefull if you have the same field multiple time in the same screen.
Example:
"name": "Reference for Layout, use slug instead"
label
- Type: String
- Description: The display name of the field. If null, the default field name is used.
Example:
"label": "Display name for field"