Computed Fields

A computed field derives its value from other fields with compute. It re-runs when a value it reads changes, can read other computed fields, and its return type is checked against the field's type. See Computed fields for editable fields (slugs), array rows and cycles.

Preview & Code

Preview
Code

How it works

fullName: {
  type: "text",
  readOnly: true,
  compute: (v) => [v.firstName, v.lastName].filter(Boolean).join(" "),
},
initials: {
  type: "text",
  readOnly: true,
  compute: (v) => (v.fullName ?? "").split(" ").filter(Boolean).map((p) => p[0].toUpperCase()).join(""),
},
  • Multi-source: fullName reads two fields; it re-runs when either changes.
  • Chained: initials reads the computed fullName; chains settle in any config order.
  • Incomplete inputs: return undefined (BMI stays empty until weight and height are filled).
  • readOnly: true fields always follow the computed value. An editable computed field follows it until the user edits it (clearing it resumes syncing).
Tip

Computed values are part of the form state: they are validated, reported to onFieldChange and submitted. Before v0.17 this example used onFieldChange + setValue; compute replaces that pattern (chains included).