Add calculated fields to a form
When you create forms using Form builder, you can use fields to display information based on responses on other fields. Such fields are called calculated fields.
For instance, you can calculate the BMI of a patient if you know the patient's height, weight, and gender.
Zenoti lets you write the logic to calculate the value for a field using JavaScript in the field's properties.
To see calculated fields in action, go to the Fitzpatrick skin score form. The Score and Fitzpatrick skin type fields are both calculated fields.
Create a form or open an existing form.
From the components list, add a component that you want to display as a calculated field.
Note
Fields such as Text field or Number field are usually used to build calculated fields.
To display the field as a calculated field, place your mouse pointer on the field and click Edit.
To ensure that users do not change the calculated value by mistake, under the Basic tab, select the Disabled check box.
It is important to make the calculated field uneditable because the field only has to display a logically calculated value by analyzing the entries on other fields.
Go to the Data tab and expand the Calculated value section.
Scroll down to and expand the JavaScript section.
To add the logic for your calculated field, in the JavaScript section, enter a custom JavaScript code.
For writing the JavaScript logic, you must know the Field key displayed under the Basic tab and the response values of the required components.
The required components are:
The component you choose to build the calculated field.
The components whose value is required to write the logic.
Click Save.
Examples
Scenario | Perform these steps |
---|---|
You want to display the BMI (Body Mass Index) of a user when they enter their height and weight in the form. | While creating the form, perform these steps:
Result: When a user enters their height and weight into the respective fields, the BMI field automatically displays their Body Mass Index by using the code that you entered while configuring the component. |
You want to display the skin score of a user by analyzing their responses in the other fields. | While creating the form, perform these steps:
Result: When a user enters responses into the radio components, the Score field automatically displays the skin score of the user by using the code that you entered while configuring the component. |
You want to display the skin type of a user by analyzing their skin score. | While creating the form, perform these steps:
Result: As soon as the Score field displays a score for the user's skin, the Fitzpatrick skin type field automatically displays the skin type of the user by using the code that you entered while configuring the component. |