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
| Index | The one-based form-field index |
|---|---|
| Action | The validation, calculation, formatting or keystroke action to execute |
| InputValue | The initial value exposed as event.value |
| OutputValue | The 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 makes the script unsupported, and SetFormScriptHostActionMode can report it 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 their active branches; logical operators return the selected operand value
Inactive branches are still parsed against the supported grammar and consume source, nesting and operation limits, but do not read field values or evaluate numeric, date or formatting conversions
An active Math.pow call requires both base and exponent; a missing exponent reports error 708 and leaves the stored field unchanged
String indexOf returns zero for an empty search string, including when the input string is empty
String charAt truncates a fractional position toward zero before checking bounds, so -0.5 selects the first UTF-16 code unit; an empty string or an out-of-range integer position produces an empty result
See also
ExecuteFormFieldScriptEvent, SetFormScriptLimits, GetFormScriptDiagnostics, RecalculateFormFields, GetFormCalculationGraphJSON, TPDFlibFormScriptAction