Computed Fields
Auto-compute field values from other responses.
FieldCraft includes two field types that derive their values from other fields:calculated for math expressions and scoring for weighted option scores with color-coded ranges.
Calculated Fields
A calculated field evaluates a math expression that references other field values. It recalculates automatically whenever a dependency changes.
Expression Syntax
Reference fields with {fieldId}. The engine replaces each reference with the field's numeric value and evaluates the result.
| Feature | Syntax | Example |
|---|---|---|
| Field reference | {fieldId} | {price} |
| Arithmetic | + - * / | {price} * {quantity} |
| Power | ^ | {height} ^ 2 |
| Parentheses | ( ) | ({a} + {b}) / 2 |
| Functions | floor ceil round abs min max | round({total} * 100) / 100 |
Expressions are parsed with a sandboxed Shunting-yard evaluator — no eval()is used. If any referenced field is missing or non-numeric, the result is null.
Config Options
| Property | Type | Description |
|---|---|---|
expression | string | Math expression with field references |
format | "number" | "currency" | "percentage" | Display format |
decimalPlaces | number | Rounding precision |
prefix | string | Display prefix (e.g., "$") |
suffix | string | Display suffix (e.g., "kg") |
visible | boolean | Whether to render the field (default true) |
Example: Order Total
Scoring Fields
A scoring field maps selected options to numeric scores and displays a total with configurable color ranges.
Score Range Properties
| Property | Type | Description |
|---|---|---|
min | number | Range lower bound (inclusive) |
max | number | Range upper bound (inclusive) |
label | string | Display label for the range |
color | string | CSS color for the indicator |
description | string | Optional description shown in the range |
Accessing Computed Values
Computed values are stored in FormState.values like any other field. Scores are additionally tracked in FormState.scores:
Dependency Graph
The engine builds a dependency graph at initialization by parsing field references in expressions. When a field value changes, only its dependents are recalculated — not the entire form. Chained dependencies (A → B → C) resolve in the correct order.