Fields

Calculations

Calculations is the field that evaluates a formula from other field values and writes the result into a read-only input.

Use this page to preserve the input attributes and understand how referenced fields drive recalculation.

Preview

Attributes

AttributePurposeImportance
input[data-formie-calculation-input]Calculations module selectorRequired
readonlyPrevents direct editing of the calculated valueRecommended
data-formie-inputGeneric Formie input markerRequired
data-formie-input-idStable input identityRequired

Behavior

The calculations module:

  • resolves live values from referenced fields
  • evaluates the configured formula whenever watched source inputs change
  • rebinds its watchers when the field tree changes

Events

Calculations emits field events around each formula evaluation.

The formie:field:calculations:before-evaluate event

Triggered right before the formula is evaluated.

js
document.addEventListener('formie:field:calculations:before-evaluate', (event) => {
  const { calculations, variables } = event.detail;

  // Only target the quote total field.
  if (calculations?.dataset.formieInputId !== 'quoteTotal') {
    return;
  }

  // Treat a blank discount input as zero before evaluation.
  if (variables.discount === '') {
    variables.discount = 0;
  }
});

The formie:field:calculations:after-evaluate event

Triggered right after the formula has been evaluated and before the result is written back into the field.

js
document.addEventListener('formie:field:calculations:after-evaluate', (event) => {
  // Format numeric results for display without changing the source fields.
  if (typeof event.detail.result === 'number') {
    event.detail.result = event.detail.result.toFixed(2);
  }
});
Last updated: May 6, 2026, 3:46 PM