Skip to main content

Calculated Fields

Calculated fields automatically compute values based on other form inputs.

Basic Calculations

To create a simple calculated field:

  1. Add a Number component to your form
  2. Go to the API tab (Technical Properties)
  3. In the Calculated Value field, enter a JavaScript formula
  4. Reference other fields using data.fieldKey

Example: Calculate total by multiplying quantity and price:

value = data.quantity * data.price;

Formatting Calculated Results

You can format the results of calculations:

  1. Use JavaScript methods to format the result
  2. Set the appropriate number of decimal places
  3. Add currency symbols or other formatting

Example: Format a currency calculation:

value = (data.quantity * data.price).toFixed(2);

Calculations with Data Grids

For calculations involving data from data grids:

  1. Reference data grid values using data.gridName[rowIndex].fieldName
  2. Use array methods to process multiple rows
  3. Consider using reduce() for summing values

Example: Calculate sum of amounts in a data grid:

value = data.lineItems.reduce(function(sum, row) {
return sum + (parseFloat(row.amount) || 0);
}, 0);

Date Calculations

To calculate with dates:

  1. Add a calculated field (Number or Text Field)
  2. In the Calculated Value field, use JavaScript date functions
  3. Convert form date strings to Date objects for calculations

Example: Calculate days between two dates:

// Calculate days between startDate and endDate
const start = new Date(data.startDate);
const end = new Date(data.endDate);
const diffTime = Math.abs(end - start);
value = Math.ceil(diffTime / (1000 * 60 * 60 * 24));