ExecuteFormFieldScript

Forms, JavaScript safety

Description

Executes the selected field action through the bounded event runtime using a value-only compatibility wrapper

The supported subset includes the form helper actions emitted by the formatting, range-validation and simple-calculation APIs, plus assignments to event.value and event.rc using arithmetic, comparisons, Boolean operators, conditionals, controlled Event, Field and Document properties, numeric conversions, string and number helpers, util.printf and common Math functions

Syntax

Delphi

Function TPDFlib.ExecuteFormFieldScript(Index: Integer; Action: TPDFlibFormScriptAction; Const InputValue: WideString; Out OutputValue: WideString): Integer;

Parameters

IndexThe one-based form-field index
ActionThe validation, calculation, formatting or keystroke action to execute
InputValueThe initial value exposed as event.value
OutputValueThe final value after successful execution

Return values

Returns 1 when the action executes and accepts the value, or 0 when the action is absent, rejects the event, is unsupported, is invalid or exceeds a configured resource limit

Rejected validation leaves LastErrorCode at zero; unsupported, invalid and over-budget scripts report codes 706, 708 and 709

Remarks

A successful calculation action writes its result to the field, while validation and formatting return their result without changing the stored field value

Host actions such as app.alert, dynamic code, global access and external I/O are never invoked; by default a host action marks the script as unsupported, although SetFormScriptHostActionMode can have it reported to the application instead

Use ExecuteFormFieldScriptEvent when keystroke changes, selection state, key modifiers, commit state or source and target field properties are required

Conditional expressions, if/else blocks and logical operators evaluate only the branch that is active; logical operators return the value of whichever operand they select

Inactive branches are still parsed against the supported grammar and count towards the source, nesting and operation limits, but they neither read field values nor perform numeric, date or formatting conversions

An active Math.pow call needs both a base and an exponent; omitting the exponent reports error 708 and leaves the stored field untouched

String indexOf returns zero for an empty search string, even when the input string is itself empty

String charAt truncates a fractional position towards zero before the bounds check, so -0.5 selects the first UTF-16 code unit; an empty string or an out-of-range integer position gives an empty result

See also

ExecuteFormFieldScriptEvent, SetFormScriptLimits, GetFormScriptDiagnostics, RecalculateFormFields, GetFormCalculationGraphJSON, TPDFlibFormScriptAction