@nocobase/plugin-flow-engine 2.1.0-beta.2 → 2.1.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -661
- package/README.md +79 -9
- package/dist/ai/ai-employees/nathan/index.d.ts +10 -0
- package/dist/ai/ai-employees/nathan/index.js +41 -0
- package/dist/ai/ai-employees/nathan/prompt.md +132 -0
- package/dist/ai/ai-employees/nathan/skills/frontend-developer/SKILLS.md +69 -0
- package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextApis.js +2 -2
- package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextEnvs.js +2 -2
- package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextVars.js +2 -2
- package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/lintAndTestJS.js +2 -2
- package/dist/ai/docs/runjs/context/block-model.md +35 -35
- package/dist/ai/docs/runjs/context/collection-field.md +53 -51
- package/dist/ai/docs/runjs/context/collection.md +39 -39
- package/dist/ai/docs/runjs/context/data-source-manager.md +40 -30
- package/dist/ai/docs/runjs/context/data-source.md +52 -44
- package/dist/ai/docs/runjs/context/element.md +44 -38
- package/dist/ai/docs/runjs/context/exit-all.md +37 -35
- package/dist/ai/docs/runjs/context/exit.md +38 -35
- package/dist/ai/docs/runjs/context/filter-manager.md +36 -30
- package/dist/ai/docs/runjs/context/form.md +57 -57
- package/dist/ai/docs/runjs/context/get-model.md +22 -21
- package/dist/ai/docs/runjs/context/get-value.md +20 -19
- package/dist/ai/docs/runjs/context/get-var.md +61 -55
- package/dist/ai/docs/runjs/context/i18n.md +17 -14
- package/dist/ai/docs/runjs/context/import-async.md +333 -45
- package/dist/ai/docs/runjs/context/init-resource.md +20 -20
- package/dist/ai/docs/runjs/context/libs.md +31 -31
- package/dist/ai/docs/runjs/context/location.md +34 -31
- package/dist/ai/docs/runjs/context/logger.md +41 -40
- package/dist/ai/docs/runjs/context/make-resource.md +27 -26
- package/dist/ai/docs/runjs/context/message.md +42 -41
- package/dist/ai/docs/runjs/context/modal.md +44 -44
- package/dist/ai/docs/runjs/context/model.md +36 -33
- package/dist/ai/docs/runjs/context/notification.md +41 -40
- package/dist/ai/docs/runjs/context/off.md +14 -14
- package/dist/ai/docs/runjs/context/on.md +30 -29
- package/dist/ai/docs/runjs/context/open-view.md +40 -40
- package/dist/ai/docs/runjs/context/render.md +37 -32
- package/dist/ai/docs/runjs/context/request.md +46 -45
- package/dist/ai/docs/runjs/context/require-async.md +28 -25
- package/dist/ai/docs/runjs/context/resource.md +34 -34
- package/dist/ai/docs/runjs/context/route.md +36 -34
- package/dist/ai/docs/runjs/context/router.md +43 -31
- package/dist/ai/docs/runjs/context/set-value.md +18 -17
- package/dist/ai/docs/runjs/context/sql.md +7 -15
- package/dist/ai/docs/runjs/context/t.md +20 -17
- package/dist/ai/docs/runjs/context/view.md +49 -46
- package/dist/ai/docs/runjs/document.md +1 -0
- package/dist/ai/docs/runjs/import-modules.md +32 -32
- package/dist/ai/docs/runjs/index.md +13 -13
- package/dist/ai/docs/runjs/jsx.md +19 -19
- package/dist/ai/docs/runjs/model/form-block-model.md +1 -3
- package/dist/ai/docs/runjs/render.md +15 -15
- package/dist/ai/docs/runjs/resource/api-resource.md +53 -53
- package/dist/ai/docs/runjs/resource/multi-record-resource.md +64 -64
- package/dist/ai/docs/runjs/resource/single-record-resource.md +55 -55
- package/dist/ai/docs/runjs/resource/sql-resource.md +57 -57
- package/dist/ai/docs/runjs/window.md +5 -5
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +12 -11
- package/dist/locale/en-US.json +1 -0
- package/dist/locale/index.d.ts +2 -0
- package/dist/locale/zh-CN.json +1 -0
- package/dist/node_modules/ses/dist/ses.cjs +1 -1
- package/dist/node_modules/ses/package.json +1 -1
- package/dist/node_modules/zod/index.cjs +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/collections/flowsql.js +1 -0
- package/dist/server/flow-surfaces/action-scope.d.ts +39 -0
- package/dist/server/flow-surfaces/action-scope.js +156 -0
- package/dist/server/flow-surfaces/apply/compiler.d.ts +13 -0
- package/dist/server/flow-surfaces/apply/compiler.js +969 -0
- package/dist/server/flow-surfaces/apply/layout.d.ts +34 -0
- package/dist/server/flow-surfaces/apply/layout.js +175 -0
- package/dist/server/flow-surfaces/apply/matching.d.ts +16 -0
- package/dist/server/flow-surfaces/apply/matching.js +181 -0
- package/dist/server/flow-surfaces/approval/blueprint-service.d.ts +84 -0
- package/dist/server/flow-surfaces/approval/blueprint-service.js +589 -0
- package/dist/server/flow-surfaces/approval/blueprint.d.ts +21 -0
- package/dist/server/flow-surfaces/approval/blueprint.js +187 -0
- package/dist/server/flow-surfaces/approval/builder.d.ts +225 -0
- package/dist/server/flow-surfaces/approval/builder.js +384 -0
- package/dist/server/flow-surfaces/approval/catalog-specs.d.ts +33 -0
- package/dist/server/flow-surfaces/approval/catalog-specs.js +156 -0
- package/dist/server/flow-surfaces/approval/index.d.ts +14 -0
- package/dist/server/flow-surfaces/approval/index.js +40 -0
- package/dist/server/flow-surfaces/approval/runtime-config.d.ts +44 -0
- package/dist/server/flow-surfaces/approval/runtime-config.js +299 -0
- package/dist/server/flow-surfaces/approval/semantic-use.d.ts +23 -0
- package/dist/server/flow-surfaces/approval/semantic-use.js +155 -0
- package/dist/server/flow-surfaces/association-title-field.d.ts +20 -0
- package/dist/server/flow-surfaces/association-title-field.js +192 -0
- package/dist/server/flow-surfaces/blueprint/compile-blocks.d.ts +14 -0
- package/dist/server/flow-surfaces/blueprint/compile-blocks.js +1029 -0
- package/dist/server/flow-surfaces/blueprint/compile-plan.d.ts +13 -0
- package/dist/server/flow-surfaces/blueprint/compile-plan.js +308 -0
- package/dist/server/flow-surfaces/blueprint/compile-reaction.d.ts +11 -0
- package/dist/server/flow-surfaces/blueprint/compile-reaction.js +72 -0
- package/dist/server/flow-surfaces/blueprint/defaults.d.ts +26 -0
- package/dist/server/flow-surfaces/blueprint/defaults.js +133 -0
- package/dist/server/flow-surfaces/blueprint/index.d.ts +12 -0
- package/dist/server/flow-surfaces/blueprint/index.js +44 -0
- package/dist/server/flow-surfaces/blueprint/normalize-document.d.ts +10 -0
- package/dist/server/flow-surfaces/blueprint/normalize-document.js +416 -0
- package/dist/server/flow-surfaces/blueprint/private-utils.d.ts +26 -0
- package/dist/server/flow-surfaces/blueprint/private-utils.js +182 -0
- package/dist/server/flow-surfaces/blueprint/public-types.d.ts +193 -0
- package/dist/server/flow-surfaces/blueprint/public-types.js +24 -0
- package/dist/server/flow-surfaces/builder.d.ts +211 -0
- package/dist/server/flow-surfaces/builder.js +1097 -0
- package/dist/server/flow-surfaces/catalog-smart.d.ts +18 -0
- package/dist/server/flow-surfaces/catalog-smart.js +239 -0
- package/dist/server/flow-surfaces/catalog-smart.projector.d.ts +15 -0
- package/dist/server/flow-surfaces/catalog-smart.projector.js +157 -0
- package/dist/server/flow-surfaces/catalog-smart.types.d.ts +99 -0
- package/dist/server/flow-surfaces/catalog-smart.types.js +24 -0
- package/dist/server/flow-surfaces/catalog.d.ts +78 -0
- package/dist/server/flow-surfaces/catalog.js +3577 -0
- package/dist/server/flow-surfaces/chart-config.d.ts +121 -0
- package/dist/server/flow-surfaces/chart-config.js +1394 -0
- package/dist/server/flow-surfaces/compose-compiler.d.ts +108 -0
- package/dist/server/flow-surfaces/compose-compiler.js +167 -0
- package/dist/server/flow-surfaces/compose-runtime.d.ts +93 -0
- package/dist/server/flow-surfaces/compose-runtime.js +375 -0
- package/dist/server/flow-surfaces/configure-options.d.ts +23 -0
- package/dist/server/flow-surfaces/configure-options.js +860 -0
- package/dist/server/flow-surfaces/constants.d.ts +351 -0
- package/dist/server/flow-surfaces/constants.js +104 -0
- package/dist/server/flow-surfaces/context.d.ts +72 -0
- package/dist/server/flow-surfaces/context.js +556 -0
- package/dist/server/flow-surfaces/contract-guard.d.ts +19 -0
- package/dist/server/flow-surfaces/contract-guard.js +402 -0
- package/dist/server/flow-surfaces/core-field-default-bindings.d.ts +12 -0
- package/dist/server/flow-surfaces/core-field-default-bindings.js +157 -0
- package/dist/server/flow-surfaces/default-action-popup.d.ts +63 -0
- package/dist/server/flow-surfaces/default-action-popup.js +322 -0
- package/dist/server/flow-surfaces/default-block-actions.d.ts +32 -0
- package/dist/server/flow-surfaces/default-block-actions.js +209 -0
- package/dist/server/flow-surfaces/errors.d.ts +47 -0
- package/dist/server/flow-surfaces/errors.js +145 -0
- package/dist/server/flow-surfaces/executor.d.ts +23 -0
- package/dist/server/flow-surfaces/executor.js +132 -0
- package/dist/server/flow-surfaces/field-binding-registry.d.ts +23 -0
- package/dist/server/flow-surfaces/field-binding-registry.js +391 -0
- package/dist/server/flow-surfaces/field-semantics.d.ts +15 -0
- package/dist/server/flow-surfaces/field-semantics.js +83 -0
- package/dist/server/flow-surfaces/filter-group.d.ts +15 -0
- package/dist/server/flow-surfaces/filter-group.js +94 -0
- package/dist/server/flow-surfaces/index.d.ts +11 -0
- package/dist/server/flow-surfaces/index.js +302 -0
- package/dist/server/flow-surfaces/locator.d.ts +28 -0
- package/dist/server/flow-surfaces/locator.js +240 -0
- package/dist/server/flow-surfaces/node-use-sets.d.ts +15 -0
- package/dist/server/flow-surfaces/node-use-sets.js +134 -0
- package/dist/server/flow-surfaces/payload-shape.d.ts +9 -0
- package/dist/server/flow-surfaces/payload-shape.js +61 -0
- package/dist/server/flow-surfaces/placement.d.ts +33 -0
- package/dist/server/flow-surfaces/placement.js +198 -0
- package/dist/server/flow-surfaces/planning/action-specs.d.ts +179 -0
- package/dist/server/flow-surfaces/planning/action-specs.js +190 -0
- package/dist/server/flow-surfaces/planning/compiler.d.ts +37 -0
- package/dist/server/flow-surfaces/planning/compiler.js +376 -0
- package/dist/server/flow-surfaces/planning/context.d.ts +30 -0
- package/dist/server/flow-surfaces/planning/context.js +139 -0
- package/dist/server/flow-surfaces/planning/created-keys.d.ts +34 -0
- package/dist/server/flow-surfaces/planning/created-keys.js +375 -0
- package/dist/server/flow-surfaces/planning/key-kind.d.ts +11 -0
- package/dist/server/flow-surfaces/planning/key-kind.js +88 -0
- package/dist/server/flow-surfaces/planning/key-persistence.d.ts +34 -0
- package/dist/server/flow-surfaces/planning/key-persistence.js +148 -0
- package/dist/server/flow-surfaces/planning/key-registry.d.ts +40 -0
- package/dist/server/flow-surfaces/planning/key-registry.js +206 -0
- package/dist/server/flow-surfaces/planning/runtime.d.ts +37 -0
- package/dist/server/flow-surfaces/planning/runtime.js +259 -0
- package/dist/server/flow-surfaces/planning/step-link.d.ts +14 -0
- package/dist/server/flow-surfaces/planning/step-link.js +104 -0
- package/dist/server/flow-surfaces/planning/types.d.ts +55 -0
- package/dist/server/flow-surfaces/planning/types.js +24 -0
- package/dist/server/flow-surfaces/public-data-surface-default-filter.d.ts +24 -0
- package/dist/server/flow-surfaces/public-data-surface-default-filter.js +152 -0
- package/dist/server/flow-surfaces/reaction/errors.d.ts +20 -0
- package/dist/server/flow-surfaces/reaction/errors.js +69 -0
- package/dist/server/flow-surfaces/reaction/field-value.d.ts +34 -0
- package/dist/server/flow-surfaces/reaction/field-value.js +181 -0
- package/dist/server/flow-surfaces/reaction/fingerprint.d.ts +16 -0
- package/dist/server/flow-surfaces/reaction/fingerprint.js +71 -0
- package/dist/server/flow-surfaces/reaction/linkage.d.ts +136 -0
- package/dist/server/flow-surfaces/reaction/linkage.js +882 -0
- package/dist/server/flow-surfaces/reaction/meta.d.ts +11 -0
- package/dist/server/flow-surfaces/reaction/meta.js +451 -0
- package/dist/server/flow-surfaces/reaction/registry.d.ts +156 -0
- package/dist/server/flow-surfaces/reaction/registry.js +206 -0
- package/dist/server/flow-surfaces/reaction/resolver.d.ts +22 -0
- package/dist/server/flow-surfaces/reaction/resolver.js +202 -0
- package/dist/server/flow-surfaces/reaction/types.d.ts +241 -0
- package/dist/server/flow-surfaces/reaction/types.js +24 -0
- package/dist/server/flow-surfaces/reaction/utils.d.ts +17 -0
- package/dist/server/flow-surfaces/reaction/utils.js +67 -0
- package/dist/server/flow-surfaces/reaction/value-expr.d.ts +15 -0
- package/dist/server/flow-surfaces/reaction/value-expr.js +209 -0
- package/dist/server/flow-surfaces/reference-guards.d.ts +19 -0
- package/dist/server/flow-surfaces/reference-guards.js +103 -0
- package/dist/server/flow-surfaces/route-sync.d.ts +47 -0
- package/dist/server/flow-surfaces/route-sync.js +392 -0
- package/dist/server/flow-surfaces/service-helpers.d.ts +42 -0
- package/dist/server/flow-surfaces/service-helpers.js +310 -0
- package/dist/server/flow-surfaces/service-utils.d.ts +108 -0
- package/dist/server/flow-surfaces/service-utils.js +811 -0
- package/dist/server/flow-surfaces/service.d.ts +814 -0
- package/dist/server/flow-surfaces/service.js +14276 -0
- package/dist/server/flow-surfaces/support-matrix.d.ts +31 -0
- package/dist/server/flow-surfaces/support-matrix.js +271 -0
- package/dist/server/flow-surfaces/surface-context.d.ts +52 -0
- package/dist/server/flow-surfaces/surface-context.js +440 -0
- package/dist/server/flow-surfaces/template-compatibility.d.ts +42 -0
- package/dist/server/flow-surfaces/template-compatibility.js +189 -0
- package/dist/server/flow-surfaces/template-display.d.ts +20 -0
- package/dist/server/flow-surfaces/template-display.js +289 -0
- package/dist/server/flow-surfaces/template-service-utils.d.ts +62 -0
- package/dist/server/flow-surfaces/template-service-utils.js +281 -0
- package/dist/server/flow-surfaces/types.d.ts +288 -0
- package/dist/server/flow-surfaces/types.js +24 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +7 -2
- package/dist/server/plugin.d.ts +0 -1
- package/dist/server/plugin.js +9 -34
- package/dist/server/repository.js +0 -5
- package/dist/server/variables/resolve.d.ts +21 -0
- package/dist/server/variables/resolve.js +79 -0
- package/dist/swagger/flow-surfaces.d.ts +5964 -0
- package/dist/swagger/flow-surfaces.examples.d.ts +1572 -0
- package/dist/swagger/flow-surfaces.examples.js +1805 -0
- package/dist/swagger/flow-surfaces.js +5322 -0
- package/dist/swagger/flow-surfaces.template-action-docs.d.ts +62 -0
- package/dist/swagger/flow-surfaces.template-action-docs.js +121 -0
- package/dist/swagger/flow-surfaces.template-schemas.d.ts +239 -0
- package/dist/swagger/flow-surfaces.template-schemas.js +255 -0
- package/dist/swagger/index.d.ts +5969 -0
- package/dist/swagger/index.js +50 -0
- package/package.json +3 -3
- /package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextApis.d.ts +0 -0
- /package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextEnvs.d.ts +0 -0
- /package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextVars.d.ts +0 -0
- /package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/lintAndTestJS.d.ts +0 -0
|
@@ -1,109 +1,109 @@
|
|
|
1
1
|
# ctx.form
|
|
2
2
|
|
|
3
|
-
The Ant Design Form instance
|
|
3
|
+
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.).
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSField** | Read/write other fields
|
|
10
|
-
| **JSItem** | Read/write same
|
|
11
|
-
| **JSColumn** | Read row or
|
|
12
|
-
| **Form
|
|
8
|
+
|------|------|
|
|
9
|
+
| **JSField** | Read/write other form fields to implement linkage, or perform calculations and validation based on other field values. |
|
|
10
|
+
| **JSItem** | Read/write same-row or other fields within sub-table items to achieve in-table linkage. |
|
|
11
|
+
| **JSColumn** | Read the current row or association field values in a table column for rendering. |
|
|
12
|
+
| **Form Actions / Workflow** | Pre-submission validation, batch updating fields, resetting forms, etc. |
|
|
13
13
|
|
|
14
|
-
> Note: `ctx.form` is only available in RunJS contexts
|
|
14
|
+
> Note: `ctx.form` is 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()`.
|
|
15
15
|
|
|
16
|
-
## Type
|
|
16
|
+
## Type Definition
|
|
17
17
|
|
|
18
18
|
```ts
|
|
19
19
|
form: FormInstance<any>;
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
`FormInstance` is the Ant Design Form
|
|
22
|
+
`FormInstance` is the instance type of Ant Design Form. Common methods are as follows.
|
|
23
23
|
|
|
24
24
|
## Common Methods
|
|
25
25
|
|
|
26
|
-
###
|
|
26
|
+
### Reading Form Values
|
|
27
27
|
|
|
28
28
|
```ts
|
|
29
|
-
//
|
|
29
|
+
// Read values of currently registered fields (defaults to rendered fields only)
|
|
30
30
|
const values = ctx.form.getFieldsValue();
|
|
31
31
|
|
|
32
|
-
//
|
|
32
|
+
// Read values of all fields (including registered but unrendered fields, e.g., hidden or inside collapsed sections)
|
|
33
33
|
const allValues = ctx.form.getFieldsValue(true);
|
|
34
34
|
|
|
35
|
-
//
|
|
35
|
+
// Read a single field
|
|
36
36
|
const email = ctx.form.getFieldValue('email');
|
|
37
37
|
|
|
38
|
-
//
|
|
38
|
+
// Read nested fields (e.g., in a sub-table)
|
|
39
39
|
const amount = ctx.form.getFieldValue(['orders', 0, 'amount']);
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
###
|
|
42
|
+
### Writing Form Values
|
|
43
43
|
|
|
44
44
|
```ts
|
|
45
|
-
// Batch update (
|
|
45
|
+
// Batch update (commonly used for linkage)
|
|
46
46
|
ctx.form.setFieldsValue({
|
|
47
47
|
status: 'active',
|
|
48
48
|
updatedAt: new Date(),
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
-
//
|
|
52
|
-
ctx.form.setFieldValue('remark', '
|
|
51
|
+
// Update a single field
|
|
52
|
+
ctx.form.setFieldValue('remark', 'Updated remark');
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
### Validation and
|
|
55
|
+
### Validation and Submission
|
|
56
56
|
|
|
57
57
|
```ts
|
|
58
|
-
// Trigger validation
|
|
58
|
+
// Trigger form validation
|
|
59
59
|
await ctx.form.validateFields();
|
|
60
60
|
|
|
61
|
-
// Trigger
|
|
61
|
+
// Trigger form submission
|
|
62
62
|
ctx.form.submit();
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
###
|
|
65
|
+
### Resetting
|
|
66
66
|
|
|
67
67
|
```ts
|
|
68
|
-
//
|
|
68
|
+
// Reset all fields
|
|
69
69
|
ctx.form.resetFields();
|
|
70
70
|
|
|
71
|
-
//
|
|
71
|
+
// Reset only specific fields
|
|
72
72
|
ctx.form.resetFields(['status', 'remark']);
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
##
|
|
75
|
+
## Relationship with Related Contexts
|
|
76
76
|
|
|
77
77
|
### ctx.getValue / ctx.setValue
|
|
78
78
|
|
|
79
|
-
| Scenario | Recommended |
|
|
80
|
-
|
|
81
|
-
| **
|
|
82
|
-
| **
|
|
79
|
+
| Scenario | Recommended Usage |
|
|
80
|
+
|------|----------|
|
|
81
|
+
| **Read/Write current field** | `ctx.getValue()` / `ctx.setValue(v)` |
|
|
82
|
+
| **Read/Write other fields** | `ctx.form.getFieldValue(name)` / `ctx.form.setFieldValue(name, v)` |
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
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.
|
|
85
85
|
|
|
86
86
|
### ctx.blockModel
|
|
87
87
|
|
|
88
|
-
|
|
|
89
|
-
|
|
90
|
-
| **Read/
|
|
91
|
-
| **
|
|
88
|
+
| Requirement | Recommended Usage |
|
|
89
|
+
|------|----------|
|
|
90
|
+
| **Read/Write form fields** | `ctx.form` (Equivalent to `ctx.blockModel?.form`, more convenient) |
|
|
91
|
+
| **Access parent block** | `ctx.blockModel` (Contains `collection`, `resource`, etc.) |
|
|
92
92
|
|
|
93
93
|
### ctx.getVar('ctx.formValues')
|
|
94
94
|
|
|
95
|
-
Form values
|
|
95
|
+
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.
|
|
96
96
|
|
|
97
97
|
## Notes
|
|
98
98
|
|
|
99
|
-
- `getFieldsValue()`
|
|
100
|
-
-
|
|
101
|
-
- `validateFields()` throws
|
|
102
|
-
- In
|
|
99
|
+
- `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)`.
|
|
100
|
+
- Paths for nested fields like sub-tables are arrays, e.g., `['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.
|
|
101
|
+
- `validateFields()` throws an error object containing `errorFields` and other information. If validation fails before submission, you can use `ctx.exit()` to terminate subsequent steps.
|
|
102
|
+
- In asynchronous scenarios like workflows or linkage rules, `ctx.form` might not be ready yet. It is recommended to use optional chaining or null checks.
|
|
103
103
|
|
|
104
104
|
## Examples
|
|
105
105
|
|
|
106
|
-
### Field
|
|
106
|
+
### Field Linkage: Display different content based on type
|
|
107
107
|
|
|
108
108
|
```ts
|
|
109
109
|
const type = ctx.form.getFieldValue('type');
|
|
@@ -114,7 +114,7 @@ if (type === 'vip') {
|
|
|
114
114
|
}
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
-
###
|
|
117
|
+
### Calculate current field based on other fields
|
|
118
118
|
|
|
119
119
|
```ts
|
|
120
120
|
const quantity = ctx.form.getFieldValue('quantity') ?? 0;
|
|
@@ -122,48 +122,48 @@ const price = ctx.form.getFieldValue('price') ?? 0;
|
|
|
122
122
|
ctx.setValue(quantity * price);
|
|
123
123
|
```
|
|
124
124
|
|
|
125
|
-
###
|
|
125
|
+
### Read/Write other columns in the same row within a sub-table
|
|
126
126
|
|
|
127
127
|
```ts
|
|
128
|
-
// ctx.namePath is current field
|
|
129
|
-
//
|
|
128
|
+
// ctx.namePath is the path of the current field in the form, e.g., ['orders', 0, 'amount']
|
|
129
|
+
// Read 'status' in the same row: ['orders', 0, 'status']
|
|
130
130
|
const rowIndex = ctx.namePath?.[1];
|
|
131
131
|
const status = ctx.form.getFieldValue(['orders', rowIndex, 'status']);
|
|
132
132
|
```
|
|
133
133
|
|
|
134
|
-
### Pre-
|
|
134
|
+
### Pre-submission Validation
|
|
135
135
|
|
|
136
136
|
```ts
|
|
137
137
|
try {
|
|
138
138
|
await ctx.form.validateFields();
|
|
139
|
-
//
|
|
139
|
+
// Validation passed, continue with submission logic
|
|
140
140
|
} catch (e) {
|
|
141
|
-
ctx.message.error('Please
|
|
141
|
+
ctx.message.error('Please check the form fields');
|
|
142
142
|
ctx.exit();
|
|
143
143
|
}
|
|
144
144
|
```
|
|
145
145
|
|
|
146
|
-
###
|
|
146
|
+
### Submit after Confirmation
|
|
147
147
|
|
|
148
148
|
```ts
|
|
149
149
|
const confirmed = await ctx.modal.confirm({
|
|
150
|
-
title: 'Confirm
|
|
151
|
-
content: '
|
|
152
|
-
okText: '
|
|
150
|
+
title: 'Confirm Submission',
|
|
151
|
+
content: 'You will not be able to modify this after submission. Continue?',
|
|
152
|
+
okText: 'Confirm',
|
|
153
153
|
cancelText: 'Cancel',
|
|
154
154
|
});
|
|
155
155
|
if (confirmed) {
|
|
156
156
|
await ctx.form.validateFields();
|
|
157
157
|
ctx.form.submit();
|
|
158
158
|
} else {
|
|
159
|
-
ctx.exit();
|
|
159
|
+
ctx.exit(); // Terminate if user cancels
|
|
160
160
|
}
|
|
161
161
|
```
|
|
162
162
|
|
|
163
163
|
## Related
|
|
164
164
|
|
|
165
|
-
- [ctx.getValue()](./get-value.md) / [ctx.setValue()](./set-value.md):
|
|
166
|
-
- [ctx.blockModel](./block-model.md):
|
|
167
|
-
- [ctx.modal](./modal.md):
|
|
168
|
-
- [ctx.exit()](./exit.md):
|
|
169
|
-
- `ctx.namePath`: current field
|
|
165
|
+
- [ctx.getValue()](./get-value.md) / [ctx.setValue()](./set-value.md): Read and write the current field value.
|
|
166
|
+
- [ctx.blockModel](./block-model.md): Parent block model; `ctx.form` is equivalent to `ctx.blockModel?.form`.
|
|
167
|
+
- [ctx.modal](./modal.md): Confirmation dialogs, often used with `ctx.form.validateFields()` and `ctx.form.submit()`.
|
|
168
|
+
- [ctx.exit()](./exit.md): Terminate the process upon validation failure or user cancellation.
|
|
169
|
+
- `ctx.namePath`: The path (array) of the current field in the form, used to construct names for `getFieldValue` / `setFieldValue` in nested fields.
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# ctx.getModel()
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Retrieves a model instance (such as `BlockModel`, `PageModel`, `ActionModel`, etc.) from the current engine or view stack based on the model `uid`. This is used in RunJS to access other models across blocks, pages, or popups.
|
|
4
4
|
|
|
5
|
-
If you only need the model or block
|
|
5
|
+
If you only need the model or block where the current execution context is located, prioritize using `ctx.model` or `ctx.blockModel` instead of `ctx.getModel`.
|
|
6
6
|
|
|
7
7
|
## Use Cases
|
|
8
8
|
|
|
9
9
|
| Scenario | Description |
|
|
10
|
-
|
|
11
|
-
| **JSBlock / JSAction** | Get
|
|
12
|
-
| **RunJS
|
|
13
|
-
| **Custom
|
|
10
|
+
|------|------|
|
|
11
|
+
| **JSBlock / JSAction** | Get models of other blocks based on a known `uid` to read or write their `resource`, `form`, `setProps`, etc. |
|
|
12
|
+
| **RunJS in Popups** | When needing to access a model on the page that opened the popup, pass `searchInPreviousEngines: true`. |
|
|
13
|
+
| **Custom Actions** | Locate forms or sub-models in the configuration panel by `uid` across view stacks to read their configuration or state. |
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type Definition
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
getModel<T extends FlowModel = FlowModel>(
|
|
@@ -24,19 +24,19 @@ getModel<T extends FlowModel = FlowModel>(
|
|
|
24
24
|
## Parameters
|
|
25
25
|
|
|
26
26
|
| Parameter | Type | Description |
|
|
27
|
-
|
|
28
|
-
| `uid` | `string` |
|
|
29
|
-
| `searchInPreviousEngines` | `boolean` | Optional,
|
|
27
|
+
|------|------|------|
|
|
28
|
+
| `uid` | `string` | The unique identifier of the target model instance, specified during configuration or creation (e.g., `ctx.model.uid`). |
|
|
29
|
+
| `searchInPreviousEngines` | `boolean` | Optional, defaults to `false`. When `true`, searches from the current engine up to the root in the "view stack," allowing access to models in upper-level engines (e.g., the page that opened a popup). |
|
|
30
30
|
|
|
31
|
-
## Return
|
|
31
|
+
## Return Value
|
|
32
32
|
|
|
33
|
-
- Returns the corresponding `FlowModel` subclass (e.g
|
|
33
|
+
- Returns the corresponding `FlowModel` subclass instance (e.g., `BlockModel`, `FormBlockModel`, `ActionModel`) if found.
|
|
34
34
|
- Returns `undefined` if not found.
|
|
35
35
|
|
|
36
|
-
## Search
|
|
36
|
+
## Search Scope
|
|
37
37
|
|
|
38
|
-
- **Default (`searchInPreviousEngines: false`)**:
|
|
39
|
-
- **`searchInPreviousEngines: true`**:
|
|
38
|
+
- **Default (`searchInPreviousEngines: false`)**: Searches only within the **current engine** by `uid`. In popups or multi-level views, each view has an independent engine; by default, it only searches for models within the current view.
|
|
39
|
+
- **`searchInPreviousEngines: true`**: Searches upwards along the `previousEngine` chain starting from the current engine, returning the first match. This is useful for accessing a model on the page that opened the current popup.
|
|
40
40
|
|
|
41
41
|
## Examples
|
|
42
42
|
|
|
@@ -49,16 +49,17 @@ if (block?.resource) {
|
|
|
49
49
|
}
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
### Access
|
|
52
|
+
### Access a model on the page from a popup
|
|
53
53
|
|
|
54
54
|
```ts
|
|
55
|
+
// Access a block on the page that opened the current popup
|
|
55
56
|
const pageBlock = ctx.getModel('page-block-uid', true);
|
|
56
57
|
if (pageBlock) {
|
|
57
58
|
pageBlock.rerender?.();
|
|
58
59
|
}
|
|
59
60
|
```
|
|
60
61
|
|
|
61
|
-
### Cross-model
|
|
62
|
+
### Cross-model read/write and trigger rerender
|
|
62
63
|
|
|
63
64
|
```ts
|
|
64
65
|
const target = ctx.getModel('other-block-uid');
|
|
@@ -68,17 +69,17 @@ if (target) {
|
|
|
68
69
|
}
|
|
69
70
|
```
|
|
70
71
|
|
|
71
|
-
###
|
|
72
|
+
### Safety check
|
|
72
73
|
|
|
73
74
|
```ts
|
|
74
75
|
const model = ctx.getModel(someUid);
|
|
75
76
|
if (!model) {
|
|
76
|
-
ctx.message.warning('Target model not
|
|
77
|
+
ctx.message.warning('Target model does not exist');
|
|
77
78
|
return;
|
|
78
79
|
}
|
|
79
80
|
```
|
|
80
81
|
|
|
81
82
|
## Related
|
|
82
83
|
|
|
83
|
-
- [ctx.model](./model.md): model
|
|
84
|
-
- [ctx.blockModel](./block-model.md): parent block
|
|
84
|
+
- [ctx.model](./model.md): The model where the current execution context is located.
|
|
85
|
+
- [ctx.blockModel](./block-model.md): The parent block model where the current JS is located; usually accessible without needing `getModel`.
|
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
# ctx.getValue()
|
|
2
2
|
|
|
3
|
-
In JSField
|
|
3
|
+
In editable field scenarios such as JSField and JSItem, use this to get the latest value of the current field. Combined with `ctx.setValue(v)`, it enables two-way binding with the form.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Scenarios
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSField** | Read user input or current form value in editable custom fields |
|
|
10
|
-
| **JSItem** | Read current cell value in
|
|
11
|
-
| **JSColumn** | Read
|
|
8
|
+
|------|------|
|
|
9
|
+
| **JSField** | Read user input or the current form value in editable custom fields. |
|
|
10
|
+
| **JSItem** | Read the current cell value in editable items of tables/sub-tables. |
|
|
11
|
+
| **JSColumn** | Read the field value of the corresponding row during table column rendering. |
|
|
12
12
|
|
|
13
|
-
> Note
|
|
13
|
+
> **Note**: `ctx.getValue()` is only available in RunJS contexts with form binding; it does not exist in scenarios without field binding, such as workflows or linkage rules.
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type Definition
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
getValue<T = any>(): T | undefined;
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
- **
|
|
21
|
+
- **Return Value**: The current field value, whose type is determined by the field's form item type; it may be `undefined` if the field is not registered or not filled.
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## Retrieval Order
|
|
24
24
|
|
|
25
|
-
`ctx.getValue()`
|
|
25
|
+
`ctx.getValue()` retrieves values in the following order:
|
|
26
26
|
|
|
27
|
-
1. **Form
|
|
28
|
-
2. **Fallback**: If the field is not in the form,
|
|
27
|
+
1. **Form State**: Prioritizes reading from the current state of the Ant Design Form.
|
|
28
|
+
2. **Fallback Value**: If the field is not in the form, it falls back to the field's initial value or props.
|
|
29
29
|
|
|
30
|
-
If the form
|
|
30
|
+
> If the form has not finished rendering or the field is not registered, it may return `undefined`.
|
|
31
31
|
|
|
32
32
|
## Examples
|
|
33
33
|
|
|
@@ -36,9 +36,9 @@ If the form is not yet rendered or the field is not registered, the result may b
|
|
|
36
36
|
```ts
|
|
37
37
|
const current = ctx.getValue();
|
|
38
38
|
if (current == null || current === '') {
|
|
39
|
-
ctx.render(<span>Please enter
|
|
39
|
+
ctx.render(<span>Please enter content first</span>);
|
|
40
40
|
} else {
|
|
41
|
-
ctx.render(<span>Current: {current}</span>);
|
|
41
|
+
ctx.render(<span>Current value: {current}</span>);
|
|
42
42
|
}
|
|
43
43
|
```
|
|
44
44
|
|
|
@@ -47,6 +47,7 @@ if (current == null || current === '') {
|
|
|
47
47
|
```tsx
|
|
48
48
|
const { Input } = ctx.libs.antd;
|
|
49
49
|
|
|
50
|
+
// Read current value as default value
|
|
50
51
|
const defaultValue = ctx.getValue() ?? '';
|
|
51
52
|
|
|
52
53
|
ctx.render(
|
|
@@ -59,6 +60,6 @@ ctx.render(
|
|
|
59
60
|
|
|
60
61
|
## Related
|
|
61
62
|
|
|
62
|
-
- [ctx.setValue()](./set-value.md)
|
|
63
|
-
- [ctx.form](./form.md)
|
|
64
|
-
- `js-field:value-change
|
|
63
|
+
- [ctx.setValue()](./set-value.md) - Set the current field value, used with `getValue` for two-way binding.
|
|
64
|
+
- [ctx.form](./form.md) - Ant Design Form instance, for reading/writing other fields.
|
|
65
|
+
- `js-field:value-change` - Container event triggered when external values change, used to update the display.
|
|
@@ -1,94 +1,97 @@
|
|
|
1
1
|
# ctx.getVar()
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Asynchronously reads variable values from the current runtime context. Variable resolution is consistent with `{{ctx.xxx}}` in SQL and templates, typically originating from the current user, current record, view parameters, popup context, etc.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock / JSField** | Get current record, user, resource, etc
|
|
10
|
-
| **Linkage /
|
|
11
|
-
| **Formulas /
|
|
8
|
+
|------|------|
|
|
9
|
+
| **JSBlock / JSField** | Get information about the current record, user, resource, etc., for rendering or logic. |
|
|
10
|
+
| **Linkage Rules / FlowEngine** | Read `ctx.record`, `ctx.formValues`, etc., for conditional logic. |
|
|
11
|
+
| **Formulas / Templates** | Uses the same variable resolution rules as `{{ctx.xxx}}`. |
|
|
12
12
|
|
|
13
|
-
## Type
|
|
13
|
+
## Type Definition
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
16
|
getVar(path: string): Promise<any>;
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
| Parameter | Type | Description |
|
|
20
|
-
|
|
21
|
-
| `path` | `string` | Variable path; **must start with `ctx
|
|
20
|
+
|------|------|------|
|
|
21
|
+
| `path` | `string` | Variable path; **must start with `ctx.`**. Supports dot notation and array indices. |
|
|
22
22
|
|
|
23
|
-
**
|
|
23
|
+
**Return Value**: `Promise<any>`. Use `await` to get the resolved value; returns `undefined` if the variable does not exist.
|
|
24
24
|
|
|
25
|
-
> If
|
|
25
|
+
> If a path that does not start with `ctx.` is passed, an error will be thrown: `ctx.getVar(path) expects an expression starting with "ctx.", got: "..."`.
|
|
26
26
|
|
|
27
|
-
## Common
|
|
27
|
+
## Common Variable Paths
|
|
28
28
|
|
|
29
29
|
| Path | Description |
|
|
30
|
-
|
|
31
|
-
| `ctx.record` | Current record (when form/
|
|
30
|
+
|------|------|
|
|
31
|
+
| `ctx.record` | Current record (available when a form/details block is bound to a record) |
|
|
32
32
|
| `ctx.record.id` | Current record primary key |
|
|
33
|
-
| `ctx.formValues` | Current form values (
|
|
34
|
-
| `ctx.user` | Current user |
|
|
35
|
-
| `ctx.user.id` | Current user
|
|
33
|
+
| `ctx.formValues` | Current form values (commonly used in linkage rules and FlowEngine; in form scenarios, prefer `ctx.form.getFieldsValue()` for real-time reading) |
|
|
34
|
+
| `ctx.user` | Current logged-in user |
|
|
35
|
+
| `ctx.user.id` | Current user ID |
|
|
36
36
|
| `ctx.user.nickname` | Current user nickname |
|
|
37
37
|
| `ctx.user.roles.name` | Current user role names (array) |
|
|
38
|
-
| `ctx.popup.record` | Record
|
|
39
|
-
| `ctx.popup.record.id` |
|
|
40
|
-
| `ctx.urlSearchParams` | URL query
|
|
41
|
-
| `ctx.token` | Current API
|
|
38
|
+
| `ctx.popup.record` | Record within a popup |
|
|
39
|
+
| `ctx.popup.record.id` | Primary key of the record within a popup |
|
|
40
|
+
| `ctx.urlSearchParams` | URL query parameters (parsed from `?key=value`) |
|
|
41
|
+
| `ctx.token` | Current API Token |
|
|
42
42
|
| `ctx.role` | Current role |
|
|
43
43
|
|
|
44
44
|
## ctx.getVarInfos()
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
Gets the **structural information** (type, title, sub-properties, etc.) of resolvable variables in the current context, making it easier to explore available paths. The return value is a static description based on `meta` and does not include actual runtime values.
|
|
47
47
|
|
|
48
|
-
### Type
|
|
48
|
+
### Type Definition
|
|
49
49
|
|
|
50
50
|
```ts
|
|
51
51
|
getVarInfos(options?: { path?: string | string[]; maxDepth?: number }): Promise<Record<string, any>>;
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
In the return value, each key is a variable path, and the value is the structural information for that path (including `type`, `title`, `properties`, etc.).
|
|
55
55
|
|
|
56
|
-
###
|
|
56
|
+
### Parameters
|
|
57
57
|
|
|
58
|
-
|
|
|
59
|
-
|
|
60
|
-
| `path` | `string \| string[]` |
|
|
61
|
-
| `maxDepth` | `number` |
|
|
58
|
+
| Parameter | Type | Description |
|
|
59
|
+
|------|------|------|
|
|
60
|
+
| `path` | `string \| string[]` | Truncation path; only collects the variable structure under this path. Supports `'record'`, `'record.id'`, `'ctx.record'`, `'{{ ctx.record }}'`; an array represents the merging of multiple paths. |
|
|
61
|
+
| `maxDepth` | `number` | Maximum expansion depth, default is `3`. When `path` is not provided, top-level properties have `depth=1`. When `path` is provided, the node corresponding to the path has `depth=1`. |
|
|
62
62
|
|
|
63
63
|
### Example
|
|
64
64
|
|
|
65
65
|
```ts
|
|
66
|
+
// Get the variable structure under record (expanded up to 3 levels)
|
|
66
67
|
const vars = await ctx.getVarInfos({ path: 'record', maxDepth: 3 });
|
|
67
68
|
|
|
69
|
+
// Get the structure of popup.record
|
|
68
70
|
const vars = await ctx.getVarInfos({ path: 'popup.record', maxDepth: 3 });
|
|
69
71
|
|
|
72
|
+
// Get the complete top-level variable structure (default maxDepth=3)
|
|
70
73
|
const vars = await ctx.getVarInfos();
|
|
71
74
|
```
|
|
72
75
|
|
|
73
|
-
##
|
|
76
|
+
## Difference from ctx.getValue
|
|
74
77
|
|
|
75
|
-
| Method |
|
|
76
|
-
|
|
77
|
-
| `ctx.getValue()` | JSField
|
|
78
|
-
| `ctx.getVar(path)` | Any RunJS |
|
|
78
|
+
| Method | Scenario | Description |
|
|
79
|
+
|------|----------|------|
|
|
80
|
+
| `ctx.getValue()` | Editable fields like JSField or JSItem | Synchronously gets the value of the **current field**; requires form binding. |
|
|
81
|
+
| `ctx.getVar(path)` | Any RunJS context | Asynchronously gets **any ctx variable**; path must start with `ctx.`. |
|
|
79
82
|
|
|
80
|
-
In JSField, use getValue
|
|
83
|
+
In a JSField, use `getValue`/`setValue` to read/write the current field; use `getVar` to access other context variables (such as `record`, `user`, `formValues`).
|
|
81
84
|
|
|
82
85
|
## Notes
|
|
83
86
|
|
|
84
|
-
- **Path must start with `ctx.`**: e.g
|
|
85
|
-
- **
|
|
86
|
-
- **
|
|
87
|
-
- **Form values**:
|
|
87
|
+
- **Path must start with `ctx.`**: e.g., `ctx.record.id`, otherwise an error will be thrown.
|
|
88
|
+
- **Asynchronous method**: You must use `await` to get the result, e.g., `const id = await ctx.getVar('ctx.record.id')`.
|
|
89
|
+
- **Variable does not exist**: Returns `undefined`. You can use `??` after the result to set a default value: `(await ctx.getVar('ctx.user.nickname')) ?? 'Guest'`.
|
|
90
|
+
- **Form values**: `ctx.formValues` must be retrieved via `await ctx.getVar('ctx.formValues')`; it is not directly exposed as `ctx.formValues`. In a form context, prefer using `ctx.form.getFieldsValue()` to read the latest values in real-time.
|
|
88
91
|
|
|
89
92
|
## Examples
|
|
90
93
|
|
|
91
|
-
### Current
|
|
94
|
+
### Get Current Record ID
|
|
92
95
|
|
|
93
96
|
```ts
|
|
94
97
|
const recordId = await ctx.getVar('ctx.record.id');
|
|
@@ -97,55 +100,58 @@ if (recordId) {
|
|
|
97
100
|
}
|
|
98
101
|
```
|
|
99
102
|
|
|
100
|
-
### Popup
|
|
103
|
+
### Get Record Within a Popup
|
|
101
104
|
|
|
102
105
|
```ts
|
|
103
106
|
const recordId = await ctx.getVar('ctx.popup.record.id');
|
|
104
107
|
if (recordId) {
|
|
105
|
-
ctx.message.info(`
|
|
108
|
+
ctx.message.info(`Current popup record: ${recordId}`);
|
|
106
109
|
}
|
|
107
110
|
```
|
|
108
111
|
|
|
109
|
-
### Array
|
|
112
|
+
### Read Sub-items of an Array Field
|
|
110
113
|
|
|
111
114
|
```ts
|
|
112
115
|
const roleNames = await ctx.getVar('ctx.user.roles.name');
|
|
113
|
-
// e.g
|
|
116
|
+
// Returns an array of role names, e.g., ['admin', 'member']
|
|
114
117
|
```
|
|
115
118
|
|
|
116
|
-
### Default
|
|
119
|
+
### Set Default Value
|
|
117
120
|
|
|
118
121
|
```ts
|
|
122
|
+
// getVar does not have a defaultValue parameter; use ?? after the result
|
|
119
123
|
const userName = (await ctx.getVar('ctx.user.nickname')) ?? 'Guest';
|
|
120
124
|
```
|
|
121
125
|
|
|
122
|
-
### Form
|
|
126
|
+
### Read Form Field Values
|
|
123
127
|
|
|
124
128
|
```ts
|
|
129
|
+
// Both ctx.formValues and ctx.form are for form scenarios; use getVar to read nested fields
|
|
125
130
|
const status = await ctx.getVar('ctx.formValues.status');
|
|
126
131
|
if (status === 'draft') {
|
|
127
132
|
// ...
|
|
128
133
|
}
|
|
129
134
|
```
|
|
130
135
|
|
|
131
|
-
### URL
|
|
136
|
+
### Read URL Query Parameters
|
|
132
137
|
|
|
133
138
|
```ts
|
|
134
|
-
const id = await ctx.getVar('ctx.urlSearchParams.id'); // ?id=xxx
|
|
139
|
+
const id = await ctx.getVar('ctx.urlSearchParams.id'); // Corresponds to ?id=xxx
|
|
135
140
|
```
|
|
136
141
|
|
|
137
|
-
### Explore
|
|
142
|
+
### Explore Available Variables
|
|
138
143
|
|
|
139
144
|
```ts
|
|
145
|
+
// Get the variable structure under record (expanded up to 3 levels)
|
|
140
146
|
const vars = await ctx.getVarInfos({ path: 'record', maxDepth: 3 });
|
|
141
|
-
//
|
|
147
|
+
// vars looks like { 'record.id': { type: 'string', title: 'id' }, ... }
|
|
142
148
|
```
|
|
143
149
|
|
|
144
150
|
## Related
|
|
145
151
|
|
|
146
|
-
- [ctx.getValue()](./get-value.md)
|
|
147
|
-
- [ctx.form](./form.md)
|
|
148
|
-
- [ctx.model](./model.md)
|
|
149
|
-
- [ctx.blockModel](./block-model.md)
|
|
150
|
-
- [ctx.resource](./resource.md)
|
|
151
|
-
-
|
|
152
|
+
- [ctx.getValue()](./get-value.md) - Synchronously gets the current field value (JSField/JSItem only)
|
|
153
|
+
- [ctx.form](./form.md) - Form instance; `ctx.form.getFieldsValue()` can read form values in real-time
|
|
154
|
+
- [ctx.model](./model.md) - The model where the current execution context resides
|
|
155
|
+
- [ctx.blockModel](./block-model.md) - The parent block where the current JS is located
|
|
156
|
+
- [ctx.resource](./resource.md) - The resource instance in the current context
|
|
157
|
+
- `{{ctx.xxx}}` in SQL / Templates - Uses the same resolution rules as `ctx.getVar('ctx.xxx')`
|