Smartforms

Smart forms

General YAML structure

form:
    fields:
    -   name: first
        label: Entering a number greater than 12 will show the second field
        type: number
        placeholder: Placeholder here
    -   name: second
        label: This field will only be visible if the first field has a value greater than 12
        dependsOn:
            ref:
                condition: condition-one

conditions:
-   name: condition-one
    type: greaterThan
    field: first
    value: 12

Fields

Available form field properties:

NameMandatoryDefault valueDescription
nameyesUsed in condition references and will be the key JSON data resulting from filling the form.
typenotextThe data type for the form field. Possible values are described below.
valuenoThe default value for the field. Will not override any value entered by the user. If the value doesn't match the set data type, it will be ignored.
labelyesThe text that will describe the field in the generated form. Will automatically append a semicolon (:) to the text, except when the text ends with any of the characters ., :, !, ?.
requirednoboolean or conditionIf boolean, or outcome of condition is true, the field will be marked as required. If the attribute is not specified, the field will never be required.
disablednoboolean or conditionIf boolean, or outcome of condition is true, the field will be disabled and can't be edited. If the attribute is not specified, the field will never be disabled.
visiblenoboolean or conditionIf boolean, or outcome of condition is true, the field will be visible. If false, the field will not be visible. If the attribute is not specified, the field will always be visible.
numberingnononeSets whether fields should be numbered. Possible values are: none (field will not be numbered), auto (field will be numbered), per-segment (numbering will restart for each segment), per-fieldset (numbering will restart for each fieldset), restart or reset (numbering restarts at startingNumber or 1). When not specified, the value of the parent (fieldset, segment, form) is used.
startingNumberno1The number at which numbering starts. When not specified, the value of the parent (fieldset, segment, form) is used.
numberPrefixnoA prefix for numbering. When not specified, the value of the parent (fieldset, segment, form) is used.
numberSuffixno (single space)A suffix for numbering. When not specified, the value of the parent (fieldset, segment, form) is used.

Field condition

A field can either have a condition, or a reference to a global condition. Examples are below.

Embedded condition

When embedding a condition, dependsOn will have a child named condition that has attributes name, type, field and optionally a value. These are detailed below.

An example configuration is below. Here we have two fields. One (named first) that is numeric, and ane (named second) that is a text field that will only be shown if field first has a numeric value greater than 12.

form:
    fields:
    -   name: first
        label: Entering a number greater than 12 will show the second field
        type: number
        placeholder: Placeholder here
    -   name: second
        label: This field will only be visible if the first field has a value greater than 12
        dependsOn:
            condition:
                name: condition-one
                type: greaterThan
                field: first
                value: 12
Referencing a global condition

A field can also reference a global condition. This is useful for re-using conditions in multiple fields.

This example is the same as in the previous section, but in this case field second references a global condition, called condition-one. This field too, will only be shown if field first has a value greater than 12.

form:
    fields:
    -   name: first
        label: Entering a number greater than 12 will show the second field
        type: number
        placeholder: Placeholder here
    -   name: second
        label: This field will only be visible if the first field has a value greater than 12
        dependsOn:
            ref:
                condition: condition-one

conditions:
-   name: condition-one
    type: greaterThan
    field: first
    value: 12

Data types

Supported data types:

NameDescription
textPlain text.
checkboxCheck box for true/false values.
dateDate field.
numberNumeric values.
Additional attributes

Specific types of input fields support additional attributes:

Text field attributes
NameMandatoryTypeDescription
valuenostringThe value for this text field.
placeholdernostringThe placeholder value (input field hint) for this field
Number field attributes
NameMandatoryTypeDescription
valuenonumberThe value for this number field.
minnonumberThe minimal value for this number field.
maxnonumberThe maximum value for this number field.
stepnonumberThe stepping (interval) for this number field.
Select field attributes
NameMandatoryTypeDescription
valuenostringThe value for this select field. May be empty.
itemsyesarray of select field item items (see below)The items which can be selected in this select field.
Select field item
NameMandatoryTypeDescription
labelnostringThe label of the select field item. When not specified, the value attribute is used instead.
valueyesstringThe value for the select field item.
Date field attributes
NameMandatoryTypeDescription
valuenodateThe value for this date field.
minYearnonumberThe lowest year that can be picked. Defaults to 2000.
maxYearnonumberThe highest year that can be picked. Defaults to 2100.

Conditions

A number of conditions types have been defined. Most take a target field and return a boolean value, though some may need extra details. They are detailed below.

Condition types

Supported condition types:

NameReferences fieldDescription
valueSetyesChecks if the target field has a value set.
valueEmptyyesChecks if the target field has no value set. Inverse of valueSet.
allnoChecks if all supplied subconditions are true. Subconditions are given as an array of Condition (see this table).
anynoChecks if at least one supplied subconditions is true. Subconditions are given as an array of Condition (see this table).
isTrueyesChecks if the target field has a true value.
isFalseyesChecks if the target field has a false value.
greaterThanyesChecks if the target field has a value that is greater than that of the supplied value attribute.
greaterThanOrEqualyesChecks if the target field has a value that is greater than or equal to that of the supplied value attribute.
equalyesChecks if the target field has a value that is equal to that of the supplied value attribute. Supports both text and numbers.
lessThanyesChecks if the target field has a value that is less than that of the supplied value attribute.
lessThanOrEqualyesChecks if the target field has a value that is less than or equal to that of the supplied value attribute.

Conditions referencing a field must have an attribute:

NameMandatoryTypeDescription
fieldyesstringThe name of the field to which this condition refers.

Did this page help you?