Event System
Events are declared on anyUINode via the events property. Each key is a component event name, and the value is a single EventConfig or an array of them.
EventConfig Fields
| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | "script", "scriptRef", "emit", "store-action", or "bus-event" |
target | string | Yes | Inline code, script name, event name, or action name depending on type |
params | Record<string, any> | No | Parameters passed to the handler |
condition | string | No | JS expression; handler only fires when truthy |
debounce | number | No | Milliseconds to wait before executing (resets on each trigger) |
Handler Types
script— evaluatestargetas an inline JavaScript expression with access toctxand thekodexa.*bridge.scriptRef— calls a named function from the form’sscriptsorscriptModulesregistry.emit— re-emits the event from the schema root so parent components can listen.store-action— dispatches a Pinia store action (reserved for future use).bus-event— publishes on the application event bus (reserved for future use).
Example: Click and Change Handlers
EventConfig objects. Each handler’s condition is evaluated independently.
QuickJS Runtime
All scripts run in a QuickJS WebAssembly sandbox — isolated from the browser, memory-safe, and protected by a configurable execution timeout.Timeout Configuration
"Script error: interrupted" error.
Defining Scripts
Inline — short expressions placed directly inevents[].target:
scripts dictionary:
scriptRef event handlers or computed bindings on a UINode.
Script Modules
For scripts that need documentation and input/output metadata, usescriptModules. A ScriptModule wraps a function with additional fields:
| Field | Type | Description |
|---|---|---|
source | string | The JavaScript function body |
description | string | Human-readable purpose |
inputs | Record<string, string> | Expected input descriptions (documentation only) |
returns | string | Return type description |
debounce | number | Default debounce in milliseconds |
Document API
Scripts can access the current document through theloadDocument() 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.
Document Methods
| Method | Returns | Description |
|---|---|---|
getAllDataObjects() | DataObject[] | Every data object in the document |
getDataObjectByUUID(uuid) | DataObject or null | Lookup by UUID |
getDataObjectsByPath(path) | DataObject[] | All objects matching the given path |
getMetadata() | object | Document-level metadata |
Data Object Methods
| Method | Returns |
|---|---|
getPath() | Object path (e.g., "invoice/lineItem") |
getIDString() | String ID |
getUUID() | UUID string |
getName() | Display name |
getAttributes() | All attributes as an array |
getAttributeByName(name) | First attribute matching by tag or path suffix |
getAttributesByName(name) | All attributes matching by tag or path suffix |
getAttribute(label) | Attribute matching by exact tag or path |
getChildren() | Child data objects |
getChildrenByPath(path) | Children filtered by path |
getParent() | Parent data object or null |
hasTaxonomy() | Whether the object has a taxonomy reference |
Attribute Methods
| Method | Returns |
|---|---|
getValue() | Typed value (see priority below) |
getStringValue() | String representation |
getTag() | Taxonomy tag |
getPath() | Full attribute path |
getConfidence() | Extraction confidence score |
getDataFeatures() | Feature map |
getValue() returns the first non-null value in this priority order: decimal, boolean, date, dateTime, integer, string.
Write Operations
To mutate the document, obtain a writable proxy through the bridge:- Document:
createDataObject({path, taxonomyRef?}),deleteDataObject(uuid) - Data object:
addAttribute({tag, path, value?}),addChild({path}) - Attribute:
setValue(value),setStringValue(value)
document:read and data:write bridge permissions.
Example: Sum Line Item Amounts
Script Triggers
Script triggers react to changes in data attribute values. They are declared as ascriptTriggers 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) |
lineItem/amount or lineItem/quantity changes, the recalcTotal script runs after a 300ms debounce window.
Event Triggers
Event triggers react to WASM document events such as attribute changes, object creation, and validation results. They are declared as aneventTriggers array on the form.
| Field | Type | Description |
|---|---|---|
on | string | Event type: "changed:dataAttribute", "created:dataObject", "validation:dataAttribute" |
script | string | Named script reference |
filter | object | Optional {path?, dataObjectUUID?} to narrow the scope |
debounce | number | Milliseconds to debounce (default 300) |
deleted:dataObject, deleted:dataAttribute, recalculated:dataAttribute, and validationCleared:dataAttribute. Use these with event triggers to keep form state synchronized with document changes.
Next Steps
Bridge API
Full kodexa.* API reference with permissions and service bridges
Data Binding
Context variables, expressions, and scoped data
