Add dynamic behavior to Kodexa data forms with event handlers, the QuickJS runtime, the document API, and reactive triggers that respond to data changes.
Use this file to discover all available pages before exploring further.
V2 data forms combine a declarative event system with a sandboxed JavaScript runtime to add dynamic behavior to forms. Events are attached to components, scripts run in QuickJS WebAssembly, and triggers react to changes in the underlying document. This page covers all four pieces and how they fit together.
Events are declared on any UINode via the events property. Each key is a component event name, and the value is a single EventConfig or an array of them.
Scripts can access the current document through the loadDocument() global, which returns a read-only document proxy. This API mirrors the server-side Goja document wrappers, so scripts work the same way in both environments.
function(ctx) { var doc = loadDocument(); var lineItems = doc.getDataObjectsByPath("invoice/lineItem"); var total = 0; for (var i = 0; i < lineItems.length; i++) { var amt = lineItems[i].getAttributeByName("amount"); if (amt) { total += Number(amt.getValue()) || 0; } } return total;}
Script triggers react to changes in data attribute values. They are declared as a scriptTriggers array on the form definition and invoke a named script whenever one of the watched attribute paths changes.
Field
Type
Description
script
string
Named script reference from scripts or scriptModules
triggerOn
string[]
Attribute paths to watch (e.g., ["lineItem/amount"])
debounce
number
Milliseconds to debounce (default 0)
{ "version": "2", "scripts": { "recalcTotal": "function(ctx) { var doc = loadDocument(); var items = doc.getDataObjectsByPath('invoice/lineItem'); var sum = 0; for (var i = 0; i < items.length; i++) { var a = items[i].getAttributeByName('amount'); if (a) sum += Number(a.getValue()) || 0; } return sum; }" }, "scriptTriggers": [ { "script": "recalcTotal", "triggerOn": ["lineItem/amount", "lineItem/quantity"], "debounce": 300 } ]}
When any attribute matching lineItem/amount or lineItem/quantity changes, the recalcTotal script runs after a 300ms debounce window.
Event triggers react to WASM document events such as attribute changes, object creation, and validation results. They are declared as an eventTriggers array on the form.
Optional {path?, dataObjectUUID?} to narrow the scope
debounce
number
Milliseconds to debounce (default 300)
{ "version": "2", "scripts": { "validateAmount": "function(ctx) { var doc = loadDocument(); var obj = doc.getDataObjectByUUID(ctx.dataObjectUUID); if (!obj) return; var amt = obj.getAttributeByName('amount'); if (amt && Number(amt.getValue()) < 0) { kodexa.log.warn('Negative amount detected', ctx.dataObjectUUID); } }" }, "eventTriggers": [ { "on": "changed:dataAttribute", "script": "validateAmount", "filter": { "path": "lineItem/amount" }, "debounce": 500 } ]}
Additional event types emitted by the WASM layer include deleted:dataObject, deleted:dataAttribute, recalculated:dataAttribute, and validationCleared:dataAttribute. Use these with event triggers to keep form state synchronized with document changes.