Calculation Support v2.1

Native Form Maker provides a high-performance calculation engine that runs entirely on the client. This guide covers how to build formulas that react instantly to user input.

Core Principle Calculations are dynamic. The moment a user changes an input, the engine re-evaluates the dependency graph and updates all downstream fields.

How it Works

When you mark a field as Calculated Field = Yes, it becomes read-only by default (though you can toggle this). The engine uses a safe JSEP-based evaluator which prevents arbitrary code execution while remaining extremely fast.

Formula Syntax

Use field Keys (the technical name, usually prefixed with fh_) instead of labels. Formulas support standard arithmetic and logic.

Formula Example
fh_quantity * fh_unit_price * (1 - fh_discount_pct / 100)

Native Functions

Beyond standard math, the engine provides built-in functions for common business logic.

Logical Functions

  • if(condition, trueVal, falseVal): Standard ternary logic.
  • round(val, precision): Clamps a number to specified decimal places.
  • min(a, b, ...) and max(a, b, ...): Returns the smallest or largest value.
Best Practice Always wrap currency results in round(..., 2) to avoid floating-point artifacts like 19.999999999.

Repeater Rollups

One of the most powerful features is the ability to aggregate data from repeater rows into the top-level form.

  • sumRows('repeater_key', 'child_key')
  • countRows('repeater_key')
  • avgRows('repeater_key', 'child_key')

Pro Examples

Guarded Division

Prevents Infinity or NaN results when dividing by potentially zero values.

Safe Divide
if(fh_count == 0, 0, fh_total / fh_count)

Dynamic Tax Logic

Calculates tax only if the fh_taxable toggle is active.

Conditional Logic
if(fh_taxable, fh_subtotal * 0.0825, 0)