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.).
| Scenario | Description |
|---|---|
| JSField | Read/write other form fields to implement linkage, or perform calculations and validation based on other field values. |
| JSItem | Read/write same-row or other fields within sub-table items to achieve in-table linkage. |
| JSColumn | Read the current row or association field values in a table column for rendering. |
| Form Actions / Workflow | Pre-submission validation, batch updating fields, resetting forms, etc. |
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().
FormInstance is the instance type of Ant Design Form. Common methods are as follows.
| Scenario | Recommended Usage |
|---|---|
| Read/Write current field | ctx.getValue() / ctx.setValue(v) |
| Read/Write other fields | ctx.form.getFieldValue(name) / ctx.form.setFieldValue(name, v) |
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.
| Requirement | Recommended Usage |
|---|---|
| Read/Write form fields | ctx.form (Equivalent to ctx.blockModel?.form, more convenient) |
| Access parent block | ctx.blockModel (Contains collection, resource, etc.) |
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.
getFieldsValue() returns only rendered fields by default. To include unrendered fields (e.g., in collapsed sections or hidden by conditional rules), pass true: getFieldsValue(true).['orders', 0, 'amount']. You can use ctx.namePath to get the current field's path and construct paths for other columns in the same row.validateFields() throws an error object containing errorFields and other information. If validation fails before submission, you can use ctx.exit() to terminate subsequent steps.ctx.form might not be ready yet. It is recommended to use optional chaining or null checks.ctx.form is equivalent to ctx.blockModel?.form.ctx.form.validateFields() and ctx.form.submit().ctx.namePath: The path (array) of the current field in the form, used to construct names for getFieldValue / setFieldValue in nested fields.