The Calculation field

Prev Next

Overview

With the Calculation field, you can set up basic calculations in your forms, such as adding two or more fields together. This can be useful for calculating measurements, costs, safety scores, and any other values in real time. This helps to streamline data collection and reduces the risk of human error. You are also able to use most standard JavaScript within the formula for more advanced calculations.  

How to set up a calculation

  1. Add a Calculation field to the form you are building in the Form Builder.

  2. Select the green Add Calculation button in the settings menu on the right. Add Calculation button in the field settings menu

  3. This window is where you'll be writing your calculations—simple or complex.

    • On the left is a list of all the fields in your form (except other calculation fields). You can use other calculation fields in your calculations, but you will need to enter them manually.

  4. You can now select your fields to add them to the window on the right.

    • This click-to-add system will automatically add the field key and the $ symbol on each side of the field key.

    • As an option, you can also manually enter the field key you want to target, surrounded by the $ symbol. Read more about the $ symbol below:

  5. Enter your desired calculations in the Calculation Formula box. The Calculation Formula accepts standard JavaScript. Learn more about scripting rules/calculations.

$ symbol

The $ symbol is an important part of performing calculations in the Calculation field. The $ symbol essentially tells the Calculation field that the very next set of numbers and letters is a field key, and it will continue to do so until you end with another $. So your field key should look something like this when placed in the Calculation field:

$numeric_1$

In the example, numeric_1 is your unique field key. The first $ tells the Calculation to START reading unique field key, and the end $ tells it to STOP reading the unique field key. Calculation field showing a field key wrapped in dollar signs

Validator tool

The Validator Tool checks if your calculation is valid. It will be able to check scripts and standard calculations. That being said, it will not be able to find every issue. Its functionality is mainly intended to give you an idea of what kind of problems are in your scripts and calculations, if any. The Validator Tool can also check a few rules issues.  To use the Validator Tool:

  1. Make sure you are in the Form Builder in the FastField Portal

  2. Select Advanced Options > Validate Form

Configuration

Setting

Description

Field Label

The label displayed for the field. This is usually displayed at the top left corner above the field.

Field Key

A key used to reference the field in submission data. The key is also used to reference the field in rules and calculations.

Default Value

The value that will be used to pre-populate the field when the form is initially opened.

Decimal Positions

The number of decimal positions to show in the value.

Field Rules

A Rule or JavaScript snippet that allows you to perform actions on fields or sections within the form. The actions can include hide, show, enable, disable, showSection, and hideSection. Rules are executed on field value changes and when the form is opened.

ex.

if ($field1$ > 23) { hide(); } else { show(); }

(Learn more about field rules and skip logic.)

Hide Question

Hides the Field Name label.

Hidden

If enabled the field and all labels are not visible.

Exclude Report

If checked, the field will be excluded from HTML and PDF reports and will also be excluded from Excel and CSV exports.

Exclude Sync

If enabled the value of the field will not be submitted in the form submission.

Force String Output

Treats the output of the Calculation field as a text string whether or not the output is a string, number, or some other JavaScript value.

Calculation Formula

A JavaScript snippet that allows you to perform mathematical functions on fields within the form.

ex.

return $field1$ * $field2$;

(Learn more about field rules and skip logic.)

Color

Choose a theme to change the background and font colors of the field cell as displayed in the apps.

Result Data

Data Type

Domain of Values

Example JSON

String

N/A

{ "computed_1": "555-55-5555" }