bindings, named functions in the scripts registry, and fully-described scriptModules with metadata. All script execution happens within a secure sandbox with configurable time limits and explicit permission controls.
This guide covers how to write scripts, where to place them, how the QuickJS sandbox works, and how to debug scripts at runtime. For the full list of bridge methods available to scripts, see the Bridge API reference.
Understanding the scripting model is key to building dynamic V2 forms. While simple forms can rely entirely on props and basic bindings, scripts unlock computed values, validation logic, conditional formatting, and custom event handling.
Inline Expressions in Bindings
The simplest form of scripting is an inline expression in abindings entry. Each binding value is a JavaScript expression evaluated against the data context (ctx).
ctx variable, which contains the current data context. In a loop (for), the context also includes $item, $index, $parent, and $root.
Binding expressions should be pure and side-effect-free. They are re-evaluated whenever the data context changes. If you need to perform side effects (API calls, data mutations), use event handlers instead.
Expression Syntax
Expressions are standard JavaScript. They are wrapped in an immediately-invoked function by the runtime:Named Scripts in the Scripts Registry
For reusable logic, register named scripts in the top-levelscripts object. Each entry is a function that receives a context parameter and returns a value.
Referencing Named Scripts
Named scripts can be used in two ways: 1. Incomputed bindings:
The computed object on a UINode maps prop names to script names. The script is called with the current data context and its return value becomes the prop value.
scriptRef event handlers:
Use the scriptRef event type to call a named script when an event fires.
ScriptModule with Metadata
For scripts that need documentation, type information, or debounce behavior, usescriptModules instead of the flat scripts registry. A ScriptModule wraps a script function with additional metadata.
| Field | Type | Description |
|---|---|---|
source | string | The JavaScript function body |
description | string | Human-readable description |
inputs | Record<string, string> | Expected input types (documentation only, not enforced) |
returns | string | Return type description |
debounce | number | Default debounce in milliseconds |
computed bindings or scriptRef event handlers.
QuickJS Sandbox
V2 form scripts run inside a QuickJS WebAssembly sandbox, not in the browser’s main JavaScript engine. This provides several security guarantees:Security Model
- No DOM access: Scripts cannot access
document,window, or any browser APIs. - No network access: Scripts cannot make
fetchorXMLHttpRequestcalls directly. Usekodexa.httpbridge methods instead. - No file system: Scripts cannot read or write files.
- No
evalorFunction: Dynamic code generation is not available inside the sandbox. - Execution time limit: Each script evaluation is interrupted if it exceeds
maxExecutionMs(default: 1000ms). Configure this in thebridgesection.
What Is Available
Inside the QuickJS sandbox, scripts have access to:- Standard JavaScript: Variables, functions, operators, ternary, optional chaining, destructuring, template literals
ctxobject: The data context withdataObjects,tagMetadataMap, and loop variableskodexa.*bridge: The bridge API (when called from event handlers). See Bridge API- JSON:
JSON.parse()andJSON.stringify() - Math: The full
Mathobject - Array/String methods: All standard built-in methods
Execution Time Limits
The sandbox uses an interrupt handler that checks elapsed time between operations. If a script exceeds the configured limit, it is terminated and throws an error.The default limit is 1000ms. For forms with heavy computation (large array processing, complex aggregations), consider increasing this value. However, long-running scripts will block the UI, so optimize your logic where possible.
Debugging Scripts
Using kodexa.log
Thekodexa.log namespace provides logging methods that output to the browser’s developer console with a [DataFormV2] prefix:
| Method | Console Method | When to Use |
|---|---|---|
kodexa.log.debug(...) | console.debug | Development-time tracing |
kodexa.log.warn(...) | console.warn | Unexpected but recoverable situations |
kodexa.log.error(...) | console.error | Errors that should be investigated |
Common Script Errors
Script error: undefined is not a function This usually means you are trying to call a method that is not available in the QuickJS sandbox (e.g.,fetch, setTimeout).
Script error: interrupted
The script exceeded maxExecutionMs. Look for infinite loops or expensive operations.
Script “myScript” not found
The scriptRef target does not match any key in scripts or scriptModules. Check for typos.
Permission denied: data:write
The script tried to call a bridge method that requires a permission not listed in bridge.permissions. Add the required permission to the form’s bridge configuration.
