ctx.collectionField
The CollectionField instance associated with the current RunJS execution context, used to access field metadata, types, validation rules, and association information. It only exists when the field is bound to a collection definition; custom/virtual fields may be null.
Use Cases
Note:
ctx.collectionFieldis only available when the field is bound to a Collection definition; it is usuallyundefinedin scenarios like JSBlock independent blocks or action events without field binding. It is recommended to check for null values before use.
Type Definition
Common Properties
Common Methods
Examples
Branch rendering based on field type
Determine if it is an association field and access the target collection
Get enumeration options
Conditional rendering based on read-only/view mode
Get the title field of the target collection
Relationship with ctx.collection
ctx.collection usually represents the collection bound to the current block; ctx.collectionField represents the definition of the current field in the collection. In scenarios like sub-tables or association fields, the two may differ.
Notes
- In scenarios such as JSBlock or JSAction (without field binding),
ctx.collectionFieldis usuallyundefined. It is recommended to use optional chaining before access. - If a custom JS field is not bound to a collection field,
ctx.collectionFieldmay benull. targetCollectiononly exists for association type fields (e.g., m2o, o2m, m2m);enumonly exists for fields with options like select or radioGroup.
Related
- ctx.collection: Collection associated with the current context
- ctx.model: Model where the current execution context is located
- ctx.blockModel: Parent block carrying the current JS
- ctx.getValue(), ctx.setValue(): Read and write the current field value

