ctx.form
The Ant Design Form instance within the current block, used to read/write form fields, trigger validation, and submission. It is equivalent to ctx.blockModel?.form and can be used directly in form-related blocks (Form, Edit Form, Sub-form, etc.).
Use Cases
Note:
ctx.formis only available in RunJS contexts related to form blocks (Form, Edit Form, Sub-form, etc.). It may not exist in non-form scenarios (such as independent JSBlocks or Table blocks). It is recommended to perform a null check before use:ctx.form?.getFieldsValue().
Type Definition
FormInstance is the instance type of Ant Design Form. Common methods are as follows.
Common Methods
Reading Form Values
Writing Form Values
Validation and Submission
Resetting
Relationship with Related Contexts
ctx.getValue / ctx.setValue
Within the current JS field, prioritize using getValue/setValue to read/write the field itself; use ctx.form when you need to access other fields.
ctx.blockModel
ctx.getVar('ctx.formValues')
Form values must be obtained via await ctx.getVar('ctx.formValues') and are not directly exposed as ctx.formValues. In a form context, it is preferred to use ctx.form.getFieldsValue() to read the latest values in real-time.
Notes
getFieldsValue()returns only rendered fields by default. To include unrendered fields (e.g., in collapsed sections or hidden by conditional rules), passtrue:getFieldsValue(true).- Paths for nested fields like sub-tables are arrays, e.g.,
['orders', 0, 'amount']. You can usectx.namePathto get the current field's path and construct paths for other columns in the same row. validateFields()throws an error object containingerrorFieldsand other information. If validation fails before submission, you can usectx.exit()to terminate subsequent steps.- In asynchronous scenarios like workflows or linkage rules,
ctx.formmight not be ready yet. It is recommended to use optional chaining or null checks.
Examples
Field Linkage: Display different content based on type
Calculate current field based on other fields
Read/Write other columns in the same row within a sub-table
Pre-submission Validation
Submit after Confirmation
Related
- ctx.getValue() / ctx.setValue(): Read and write the current field value.
- ctx.blockModel: Parent block model;
ctx.formis equivalent toctx.blockModel?.form. - ctx.modal: Confirmation dialogs, often used with
ctx.form.validateFields()andctx.form.submit(). - ctx.exit(): Terminate the process upon validation failure or user cancellation.
ctx.namePath: The path (array) of the current field in the form, used to construct names forgetFieldValue/setFieldValuein nested fields.

