A calculation is a mathematical formula based on the user’s input when filling out the form. The result is a number or true/false. We may for instance calculate the cost of goods delivered when the cost per piece and the number of pieces have been entered. Calculations can be defined for Number, Decimal, Text Input, Text Input Area, Date, Time and Date and Time elements.
Validation logic evaluates whether the input given is OK, e.g. if the age entered by the user is within a certain interval, and gives a message about this. Validations can be defined for Number, Decimal, Text Input, Text Input Area, Date, Time, Boolean, Single Select, Multiple Select, Slider, Location Capture and Repeat elements.
Add a calculation formula
- When you have defined one or more elements you wish to do a calculation for, add a new element for the calculation. This can be a Number, Text Input, Text Input Area, Date or Time
- In the new calculation element’s Properties, go to the Rules tab and press [Add] next to Calculation.
- In the Rule Logic tab, choose the Operator or Function or Macro you want to use and drag it to the left pane Calculation Formula.
- Complete the formula in the left pane by dragging over Element References from the tab Form Elements.
– Use [Text/String] to enter a simple number, word or string.
– If you make a mistake, drag the unwanted item to the Hold area – Recycle bin in the bottom right pane. - Press [OK] to go back to the Designer screen.
- In the Preview panel, type a number in the first element(s) to check if the calculation element produces the correct result.
If not, open its Calculation and redefine the Calculation Formula.
Note! If you get “NaN” as a result of your calculation, this means Not a Number. There is an error in the calculation, possibly caused from selecting [Text/String] to represent a value instead of [Number] or Element ID.
In the example shown below we have defined two Decimal elements; Cost ex VAT and Cost incl VAT. In the first of these the user will enter a base cost. The second element should then automatically show the price entered in the first one + an added VAT of 25%. This means the base cost entered should be multiplied with 1.25. This is the calculation entered in the element Cost incl VAT:
We now test the calculation in the Preview panel by typing 100 in the element Cost ex. VAT. The calculation in the Cost incl. VAT element shows the number 125, which is 100 * 1.25. We can then use this number further in additions etc.
Add validation logic
- Click on the element you want to add a validation for, and press [Add] next to Validations. This can be a Number, Text Input, Text Input Area, Date, Time, Boolean, Single Select, Multiple Select, Slider, Location Capture or Repeat
- Type a descriptive name for the validation in the top left text field Name of Validation.
- In the Rule Logic tab, choose the Operator or Function or Macro you want to use and drag it to the left pane IF NOT: Validation Formula.
- Complete the formula in the left pane by dragging over Element References from the tab Form Elements.
– Use [Text/String] to enter a simple number, word or string.
– If you make a mistake, drag the unwanted item to the Hold area – Recycle bin in the bottom right pane. - In the lower left pane THEN SHOW: Validation Message type the message that you want to show if the condition above is NOT met.
- Press [OK] to go back to the Designer screen.
- In the Preview panel, type a value in the element to check that the validation produces a message that is logically correct.
If not, open its Validation and redefine the Validation Formula.
In the example shown below we have created a message stating that participants under 18 may not fill out the form. We have then tested the validation in the Preview panel by typing 17 in the Number element Age. The validation in this element shows a message about the user not being old enough. We may also add a skip rule to the form that hides elements or pages from the users that are too young; see Designing: 5.1 Rules (branching / skip formulas).
Formula tips
- To compare two values, first drag the Operator to the left pane, then the Form Elements and/or the Values.
- To compare with a specific value, use [Text/String] or [Number] to enter the value.
- To change comparison logic, element or value, click on the item in the left pane to select other items.
Note! You may add a validation inside a repeat, but if the validation condition is not met you will not be able to save the data entered.
Note! The logic in Validations defined on a random element has an IF NOT… THEN structure. The logic in Rules defined on the top Form element has an IF… THEN structure, as explained in Designing: 5.1 Rules (branching/skip formulas).
See also Designing: 5.4 List of functions and the examples in Designing: 9 Examples.