Forms and data
How to show, require and calculate fields from other answers
Use Visible when, Required when and Calculated value to keep forms short and totals correct, with examples you can paste into the form builder.
Last updated
Long forms put people off. Conditional fields show a question only when it applies, make an answer required only when it matters and work out totals for the person. You write the rules in the form builder, using the expression language.
Show a field only when it applies
- Open the Form tab and open the field you want to control.
- In Visible when, type a rule such as
form.leaveType == 'sick'. - Leave it empty to always show the field.
The field appears as soon as the rule becomes true. When it is hidden, it is not required and any answer to it is dropped when the request is submitted.
Require a field only sometimes
Type a rule into Required when. For example, on a "Justification" field, use form.amount > 5000. If the rule is true, the field must be answered. A field that is hidden is never required, even if Required when is true.
Add a calculated value
- Add a field and set its Type to Calculated value.
- In Calculation, enter an expression such as
form.quantity * form.unitPrice. - Place the field after the fields it uses.
The person sees the result update as they type, in a read-only box. When the request is submitted, the server works the value out again and stores that result, so it cannot be edited.
Rules for fields that refer to other fields
- A rule on a form field can only use other fields of the same form, written
form.<key>. Requester details and API call results are not available there. - Fields are processed in form order. A calculated field must come after the fields it uses, including other calculated fields. Otherwise it sees an empty value.
- If any value used in arithmetic is empty or not a number, the result is empty. Make the inputs required where that matters.
- Avoid dividing by a field that can be zero.
- A calculated field is not offered as the Limit field on an approval step, which lists only Number and Currency fields. Use a Condition step on the total instead. See approval limits.
Examples
| Goal | Where | Rule |
|---|---|---|
| Ask for a doctor's note on long sick leave | Visible when | form.leaveType == 'sick' && form.days > 3 |
| Require a budget code above a threshold | Required when | form.amount >= 1000 |
| Total with tax | Calculation | form.net + form.net * 0.075 |
| Show a field for chosen regions | Visible when | contains(form.regions, 'EMEA') |
| Show a field when a box is ticked | Visible when | form.needsLaptop |
For the field types themselves, read form fields and validation. To route a request on the same answers, see conditions and branching. The forms and files module page gives an overview.