logologo
Get Started
Guide
Development
Plugins
API
Home
English
简体中文
日本語
한국어
Español
Português
Deutsch
Français
Русский
Italiano
Türkçe
Українська
Tiếng Việt
Bahasa Indonesia
ไทย
Polski
Nederlands
Čeština
العربية
עברית
हिन्दी
Svenska
Get Started
Guide
Development
Plugins
API
Home
logologo
RunJS Overview
Import Modules
Render in Container

Global Variables

window
document
navigator

ctx

ctx.blockModel
ctx.collection
ctx.collectionField
ctx.dataSource
ctx.dataSourceManager
ctx.element
ctx.exit()
ctx.exitAll()
ctx.filterManager
ctx.form
ctx.getModel()
ctx.getValue()
ctx.getVar()
ctx.i18n
ctx.importAsync()
ctx.initResource()
ctx.libs
ctx.location
ctx.logger
ctx.makeResource()
ctx.message
ctx.modal
ctx.model
ctx.notification
ctx.off()
ctx.on()
ctx.openView()
ctx.render()
ctx.request()
ctx.requireAsync()
ctx.resource
ctx.route
ctx.router
ctx.setValue()
ctx.sql
ctx.t()
ctx.view
Previous Pagectx.filterManager
Next Pagectx.getModel()

#ctx.form

The Ant Design Form instance for the current block; used to read/write form fields, trigger validation, and submit. Same as ctx.blockModel?.form; in form blocks (Form, EditForm, sub-forms, etc.) you can use it directly.

#Use Cases

ScenarioDescription
JSFieldRead/write other fields for linkage, compute or validate from other field values
JSItemRead/write same row or other fields in sub-table items
JSColumnRead row or related field values for column rendering
Form actions / event flowPre-submit validation, batch field updates, reset form, etc.

Note: ctx.form is only available in RunJS contexts tied to a form block (Form, EditForm, sub-forms, etc.); in non-form contexts (e.g. standalone JSBlock, table block) it may be absent—check before use: ctx.form?.getFieldsValue().

#Type

form: FormInstance<any>;

FormInstance is the Ant Design Form instance type.

#Common Methods

#Read form values

// Current registered field values (default: only rendered fields)
const values = ctx.form.getFieldsValue();

// All field values (including unrendered, e.g. hidden, collapsed)
const allValues = ctx.form.getFieldsValue(true);

// Single field
const email = ctx.form.getFieldValue('email');

// Nested (e.g. sub-table)
const amount = ctx.form.getFieldValue(['orders', 0, 'amount']);

#Write form values

// Batch update (e.g. linkage)
ctx.form.setFieldsValue({
  status: 'active',
  updatedAt: new Date(),
});

// Single field
ctx.form.setFieldValue('remark', 'Noted');

#Validation and submit

// Trigger validation
await ctx.form.validateFields();

// Trigger submit
ctx.form.submit();

#Reset

// All fields
ctx.form.resetFields();

// Specific fields
ctx.form.resetFields(['status', 'remark']);

#Relation to Other Context

#ctx.getValue / ctx.setValue

ScenarioRecommended
Current fieldctx.getValue() / ctx.setValue(v)
Other fieldsctx.form.getFieldValue(name) / ctx.form.setFieldValue(name, v)

In the current JS field, use getValue/setValue for that field; use ctx.form for other fields.

#ctx.blockModel

NeedRecommended
Read/write form fieldsctx.form (same as ctx.blockModel?.form)
Parent blockctx.blockModel (includes collection, resource, etc.)

#ctx.getVar('ctx.formValues')

Form values are obtained via await ctx.getVar('ctx.formValues'), not as ctx.formValues. In form contexts, prefer ctx.form.getFieldsValue() for up-to-date values.

#Notes

  • getFieldsValue() by default returns only rendered fields; for unrendered (e.g. collapsed) use getFieldsValue(true).
  • Nested paths use arrays, e.g. ['orders', 0, 'amount']; you can use ctx.namePath to build paths for other columns in the same row.
  • validateFields() throws with errorFields etc. on failure; use ctx.exit() to stop further steps when validation fails.
  • In event flow or linkage, ctx.form may not be ready yet; use optional chaining or null checks.

#Examples

#Field linkage by type

const type = ctx.form.getFieldValue('type');
if (type === 'vip') {
  ctx.form.setFieldsValue({ discount: 0.8 });
} else {
  ctx.form.setFieldsValue({ discount: 1 });
}

#Compute current field from others

const quantity = ctx.form.getFieldValue('quantity') ?? 0;
const price = ctx.form.getFieldValue('price') ?? 0;
ctx.setValue(quantity * price);

#Same row in sub-table

// ctx.namePath is current field path, e.g. ['orders', 0, 'amount']
// Same row status: ['orders', 0, 'status']
const rowIndex = ctx.namePath?.[1];
const status = ctx.form.getFieldValue(['orders', rowIndex, 'status']);

#Pre-submit validation

try {
  await ctx.form.validateFields();
  // Continue submit logic
} catch (e) {
  ctx.message.error('Please fix form errors');
  ctx.exit();
}

#Confirm then submit

const confirmed = await ctx.modal.confirm({
  title: 'Confirm submit',
  content: 'Cannot be changed after submit. Continue?',
  okText: 'OK',
  cancelText: 'Cancel',
});
if (confirmed) {
  await ctx.form.validateFields();
  ctx.form.submit();
} else {
  ctx.exit();
}

#Related

  • ctx.getValue() / ctx.setValue(): read/write current field
  • ctx.blockModel: parent block; ctx.form is ctx.blockModel?.form
  • ctx.modal: confirm dialog, often with ctx.form.validateFields() / ctx.form.submit()
  • ctx.exit(): stop flow on validation failure or cancel
  • ctx.namePath: current field path in the form (array); use for nested getFieldValue / setFieldValue names