@nocobase/plugin-flow-engine 2.1.0-alpha.9 → 2.1.0-beta.10
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/dist/ai/docs/runjs/context/block-model.md +35 -35
- package/dist/ai/docs/runjs/context/collection-field.md +51 -53
- package/dist/ai/docs/runjs/context/collection.md +39 -39
- package/dist/ai/docs/runjs/context/data-source-manager.md +30 -40
- package/dist/ai/docs/runjs/context/data-source.md +44 -52
- package/dist/ai/docs/runjs/context/element.md +38 -44
- package/dist/ai/docs/runjs/context/exit-all.md +35 -37
- package/dist/ai/docs/runjs/context/exit.md +35 -38
- package/dist/ai/docs/runjs/context/filter-manager.md +30 -36
- package/dist/ai/docs/runjs/context/form.md +57 -57
- package/dist/ai/docs/runjs/context/get-model.md +21 -22
- package/dist/ai/docs/runjs/context/get-value.md +19 -20
- package/dist/ai/docs/runjs/context/get-var.md +55 -61
- package/dist/ai/docs/runjs/context/i18n.md +14 -17
- package/dist/ai/docs/runjs/context/import-async.md +45 -333
- 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 +31 -34
- package/dist/ai/docs/runjs/context/logger.md +40 -41
- package/dist/ai/docs/runjs/context/make-resource.md +26 -27
- package/dist/ai/docs/runjs/context/message.md +41 -42
- package/dist/ai/docs/runjs/context/modal.md +44 -44
- package/dist/ai/docs/runjs/context/model.md +33 -36
- package/dist/ai/docs/runjs/context/notification.md +40 -41
- package/dist/ai/docs/runjs/context/off.md +14 -14
- package/dist/ai/docs/runjs/context/on.md +29 -30
- package/dist/ai/docs/runjs/context/open-view.md +40 -40
- package/dist/ai/docs/runjs/context/render.md +32 -37
- package/dist/ai/docs/runjs/context/request.md +45 -46
- package/dist/ai/docs/runjs/context/require-async.md +25 -28
- package/dist/ai/docs/runjs/context/resource.md +34 -34
- package/dist/ai/docs/runjs/context/route.md +34 -36
- package/dist/ai/docs/runjs/context/router.md +31 -43
- package/dist/ai/docs/runjs/context/set-value.md +17 -18
- package/dist/ai/docs/runjs/context/t.md +17 -20
- package/dist/ai/docs/runjs/context/view.md +46 -49
- package/dist/ai/docs/runjs/document.md +0 -1
- 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 +3 -1
- 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/externalVersion.js +10 -10
- package/dist/node_modules/ses/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/package.json +2 -2
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
# ctx.filterManager
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The filter connection manager that links filter forms (FilterForm) to data blocks (tables, lists, charts, etc.). Provided by `BlockGridModel`; only available in that context (e.g. pages with a filter form block).
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **Filter
|
|
10
|
-
| **Data
|
|
11
|
-
| **Linkage
|
|
12
|
-
| **Connection
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **Filter form block** | Manage connections between filter items and target blocks; refresh targets when filters change |
|
|
10
|
+
| **Data block (table/list)** | Act as filter target; bind filter conditions via `bindToTarget` |
|
|
11
|
+
| **Linkage / custom FilterModel** | In `doFilter`, `doReset`, call `refreshTargetsByFilter` to refresh targets |
|
|
12
|
+
| **Connection field config** | Use `getConnectFieldsConfig`, `saveConnectFieldsConfig` for filter–target field mapping |
|
|
13
13
|
|
|
14
|
-
> Note: `ctx.filterManager` is only available in RunJS contexts that have a `BlockGridModel` (e.g
|
|
14
|
+
> Note: `ctx.filterManager` is only available in RunJS contexts that have a `BlockGridModel` (e.g. pages with a filter form); in a plain JSBlock or standalone page it is `undefined`—check before use.
|
|
15
15
|
|
|
16
|
-
## Type
|
|
16
|
+
## Type
|
|
17
17
|
|
|
18
18
|
```ts
|
|
19
19
|
filterManager: FilterManager;
|
|
20
20
|
|
|
21
21
|
type FilterConfig = {
|
|
22
|
-
filterId: string;
|
|
23
|
-
targetId: string;
|
|
24
|
-
filterPaths?: string[];
|
|
25
|
-
operator?: string;
|
|
22
|
+
filterId: string;
|
|
23
|
+
targetId: string;
|
|
24
|
+
filterPaths?: string[];
|
|
25
|
+
operator?: string;
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
type ConnectFieldsConfig = {
|
|
@@ -33,24 +33,24 @@ type ConnectFieldsConfig = {
|
|
|
33
33
|
## Common Methods
|
|
34
34
|
|
|
35
35
|
| Method | Description |
|
|
36
|
-
|
|
37
|
-
| `getFilterConfigs()` |
|
|
38
|
-
| `getConnectFieldsConfig(filterId)` |
|
|
39
|
-
| `saveConnectFieldsConfig(filterId, config)` |
|
|
40
|
-
| `addFilterConfig(config)` |
|
|
41
|
-
| `removeFilterConfig({ filterId?, targetId?, persist? })` |
|
|
42
|
-
| `bindToTarget(targetId)` |
|
|
43
|
-
| `unbindFromTarget(targetId)` |
|
|
44
|
-
| `refreshTargetsByFilter(filterId
|
|
36
|
+
|--------|-------------|
|
|
37
|
+
| `getFilterConfigs()` | All filter connection configs |
|
|
38
|
+
| `getConnectFieldsConfig(filterId)` | Connection field config for a filter |
|
|
39
|
+
| `saveConnectFieldsConfig(filterId, config)` | Save connection field config for a filter |
|
|
40
|
+
| `addFilterConfig(config)` | Add filter config (filterId + targetId + filterPaths) |
|
|
41
|
+
| `removeFilterConfig({ filterId?, targetId?, persist? })` | Remove config by filterId and/or targetId |
|
|
42
|
+
| `bindToTarget(targetId)` | Bind filter to target block; its resource applies the filter |
|
|
43
|
+
| `unbindFromTarget(targetId)` | Unbind filter from target |
|
|
44
|
+
| `refreshTargetsByFilter(filterId or filterId[])` | Refresh target block(s) by filter |
|
|
45
45
|
|
|
46
|
-
##
|
|
46
|
+
## Concepts
|
|
47
47
|
|
|
48
|
-
- **FilterModel**:
|
|
49
|
-
- **TargetModel**:
|
|
48
|
+
- **FilterModel**: Provides filter values (e.g. FilterFormItemModel); must implement `getFilterValue()`.
|
|
49
|
+
- **TargetModel**: Data block being filtered; its `resource` must support `addFilterGroup`, `removeFilterGroup`, `refresh`.
|
|
50
50
|
|
|
51
51
|
## Examples
|
|
52
52
|
|
|
53
|
-
### Add
|
|
53
|
+
### Add filter config
|
|
54
54
|
|
|
55
55
|
```ts
|
|
56
56
|
await ctx.filterManager?.addFilterConfig({
|
|
@@ -61,23 +61,19 @@ await ctx.filterManager?.addFilterConfig({
|
|
|
61
61
|
});
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
### Refresh
|
|
64
|
+
### Refresh target blocks
|
|
65
65
|
|
|
66
66
|
```ts
|
|
67
|
-
// In doFilter / doReset of a filter form
|
|
68
67
|
ctx.filterManager?.refreshTargetsByFilter(ctx.model.uid);
|
|
69
68
|
|
|
70
|
-
// Refresh targets associated with multiple filters
|
|
71
69
|
ctx.filterManager?.refreshTargetsByFilter(['filter-1', 'filter-2']);
|
|
72
70
|
```
|
|
73
71
|
|
|
74
|
-
### Connection
|
|
72
|
+
### Connection field config
|
|
75
73
|
|
|
76
74
|
```ts
|
|
77
|
-
// Get connection configuration
|
|
78
75
|
const config = ctx.filterManager?.getConnectFieldsConfig(ctx.model.uid);
|
|
79
76
|
|
|
80
|
-
// Save connection configuration
|
|
81
77
|
await ctx.filterManager?.saveConnectFieldsConfig(ctx.model.uid, {
|
|
82
78
|
targets: [
|
|
83
79
|
{ targetId: 'table-uid', filterPaths: ['status'] },
|
|
@@ -86,17 +82,15 @@ await ctx.filterManager?.saveConnectFieldsConfig(ctx.model.uid, {
|
|
|
86
82
|
});
|
|
87
83
|
```
|
|
88
84
|
|
|
89
|
-
### Remove
|
|
85
|
+
### Remove config
|
|
90
86
|
|
|
91
87
|
```ts
|
|
92
|
-
// Delete all configurations for a specific filter
|
|
93
88
|
await ctx.filterManager?.removeFilterConfig({ filterId: 'filter-uid' });
|
|
94
89
|
|
|
95
|
-
// Delete all filter configurations for a specific target
|
|
96
90
|
await ctx.filterManager?.removeFilterConfig({ targetId: 'table-uid' });
|
|
97
91
|
```
|
|
98
92
|
|
|
99
93
|
## Related
|
|
100
94
|
|
|
101
|
-
- [ctx.resource](./resource.md):
|
|
102
|
-
- [ctx.model](./model.md):
|
|
95
|
+
- [ctx.resource](./resource.md): target block’s resource must support filter APIs
|
|
96
|
+
- [ctx.model](./model.md): current model uid for filterId / targetId
|
|
@@ -1,109 +1,109 @@
|
|
|
1
1
|
# ctx.form
|
|
2
2
|
|
|
3
|
-
The Ant Design Form instance
|
|
3
|
+
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.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSField** | Read/write other
|
|
10
|
-
| **JSItem** | Read/write same
|
|
11
|
-
| **JSColumn** | Read
|
|
12
|
-
| **Form
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **JSField** | Read/write other fields for linkage, compute or validate from other field values |
|
|
10
|
+
| **JSItem** | Read/write same row or other fields in sub-table items |
|
|
11
|
+
| **JSColumn** | Read row or related field values for column rendering |
|
|
12
|
+
| **Form actions / event flow** | Pre-submit validation, batch field updates, reset form, etc. |
|
|
13
13
|
|
|
14
|
-
> Note: `ctx.form` is only available in RunJS contexts
|
|
14
|
+
> 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()`.
|
|
15
15
|
|
|
16
|
-
## Type
|
|
16
|
+
## Type
|
|
17
17
|
|
|
18
18
|
```ts
|
|
19
19
|
form: FormInstance<any>;
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
`FormInstance` is the
|
|
22
|
+
`FormInstance` is the Ant Design Form instance type.
|
|
23
23
|
|
|
24
24
|
## Common Methods
|
|
25
25
|
|
|
26
|
-
###
|
|
26
|
+
### Read form values
|
|
27
27
|
|
|
28
28
|
```ts
|
|
29
|
-
//
|
|
29
|
+
// Current registered field values (default: only rendered fields)
|
|
30
30
|
const values = ctx.form.getFieldsValue();
|
|
31
31
|
|
|
32
|
-
//
|
|
32
|
+
// All field values (including unrendered, e.g. hidden, collapsed)
|
|
33
33
|
const allValues = ctx.form.getFieldsValue(true);
|
|
34
34
|
|
|
35
|
-
//
|
|
35
|
+
// Single field
|
|
36
36
|
const email = ctx.form.getFieldValue('email');
|
|
37
37
|
|
|
38
|
-
//
|
|
38
|
+
// Nested (e.g. sub-table)
|
|
39
39
|
const amount = ctx.form.getFieldValue(['orders', 0, 'amount']);
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
###
|
|
42
|
+
### Write form values
|
|
43
43
|
|
|
44
44
|
```ts
|
|
45
|
-
// Batch update (
|
|
45
|
+
// Batch update (e.g. 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
|
+
// Single field
|
|
52
|
+
ctx.form.setFieldValue('remark', 'Noted');
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
### Validation and
|
|
55
|
+
### Validation and submit
|
|
56
56
|
|
|
57
57
|
```ts
|
|
58
|
-
// Trigger
|
|
58
|
+
// Trigger validation
|
|
59
59
|
await ctx.form.validateFields();
|
|
60
60
|
|
|
61
|
-
// Trigger
|
|
61
|
+
// Trigger submit
|
|
62
62
|
ctx.form.submit();
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
###
|
|
65
|
+
### Reset
|
|
66
66
|
|
|
67
67
|
```ts
|
|
68
|
-
//
|
|
68
|
+
// All fields
|
|
69
69
|
ctx.form.resetFields();
|
|
70
70
|
|
|
71
|
-
//
|
|
71
|
+
// Specific fields
|
|
72
72
|
ctx.form.resetFields(['status', 'remark']);
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
##
|
|
75
|
+
## Relation to Other Context
|
|
76
76
|
|
|
77
77
|
### ctx.getValue / ctx.setValue
|
|
78
78
|
|
|
79
|
-
| Scenario | Recommended
|
|
80
|
-
|
|
81
|
-
| **
|
|
82
|
-
| **
|
|
79
|
+
| Scenario | Recommended |
|
|
80
|
+
|----------|-------------|
|
|
81
|
+
| **Current field** | `ctx.getValue()` / `ctx.setValue(v)` |
|
|
82
|
+
| **Other fields** | `ctx.form.getFieldValue(name)` / `ctx.form.setFieldValue(name, v)` |
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
In the current JS field, use `getValue`/`setValue` for that field; use `ctx.form` for other fields.
|
|
85
85
|
|
|
86
86
|
### ctx.blockModel
|
|
87
87
|
|
|
88
|
-
|
|
|
89
|
-
|
|
90
|
-
| **Read/
|
|
91
|
-
| **
|
|
88
|
+
| Need | Recommended |
|
|
89
|
+
|------|-------------|
|
|
90
|
+
| **Read/write form fields** | `ctx.form` (same as `ctx.blockModel?.form`) |
|
|
91
|
+
| **Parent block** | `ctx.blockModel` (includes `collection`, `resource`, etc.) |
|
|
92
92
|
|
|
93
93
|
### ctx.getVar('ctx.formValues')
|
|
94
94
|
|
|
95
|
-
Form values
|
|
95
|
+
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.
|
|
96
96
|
|
|
97
97
|
## Notes
|
|
98
98
|
|
|
99
|
-
- `getFieldsValue()` returns only rendered fields
|
|
100
|
-
-
|
|
101
|
-
- `validateFields()` throws
|
|
102
|
-
- In
|
|
99
|
+
- `getFieldsValue()` by default returns only rendered fields; for unrendered (e.g. collapsed) use `getFieldsValue(true)`.
|
|
100
|
+
- Nested paths use arrays, e.g. `['orders', 0, 'amount']`; you can use `ctx.namePath` to build paths for other columns in the same row.
|
|
101
|
+
- `validateFields()` throws with `errorFields` etc. on failure; use `ctx.exit()` to stop further steps when validation fails.
|
|
102
|
+
- In event flow or linkage, `ctx.form` may not be ready yet; use optional chaining or null checks.
|
|
103
103
|
|
|
104
104
|
## Examples
|
|
105
105
|
|
|
106
|
-
### Field
|
|
106
|
+
### Field linkage by 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
|
+
### Compute current field from others
|
|
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
|
+
### Same row in sub-table
|
|
126
126
|
|
|
127
127
|
```ts
|
|
128
|
-
// ctx.namePath is
|
|
129
|
-
//
|
|
128
|
+
// ctx.namePath is current field path, e.g. ['orders', 0, 'amount']
|
|
129
|
+
// Same row status: ['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-submit validation
|
|
135
135
|
|
|
136
136
|
```ts
|
|
137
137
|
try {
|
|
138
138
|
await ctx.form.validateFields();
|
|
139
|
-
//
|
|
139
|
+
// Continue submit logic
|
|
140
140
|
} catch (e) {
|
|
141
|
-
ctx.message.error('Please
|
|
141
|
+
ctx.message.error('Please fix form errors');
|
|
142
142
|
ctx.exit();
|
|
143
143
|
}
|
|
144
144
|
```
|
|
145
145
|
|
|
146
|
-
###
|
|
146
|
+
### Confirm then submit
|
|
147
147
|
|
|
148
148
|
```ts
|
|
149
149
|
const confirmed = await ctx.modal.confirm({
|
|
150
|
-
title: 'Confirm
|
|
151
|
-
content: '
|
|
152
|
-
okText: '
|
|
150
|
+
title: 'Confirm submit',
|
|
151
|
+
content: 'Cannot be changed after submit. Continue?',
|
|
152
|
+
okText: 'OK',
|
|
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();
|
|
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`:
|
|
165
|
+
- [ctx.getValue()](./get-value.md) / [ctx.setValue()](./set-value.md): read/write current field
|
|
166
|
+
- [ctx.blockModel](./block-model.md): parent block; `ctx.form` is `ctx.blockModel?.form`
|
|
167
|
+
- [ctx.modal](./modal.md): confirm dialog, often with `ctx.form.validateFields()` / `ctx.form.submit()`
|
|
168
|
+
- [ctx.exit()](./exit.md): stop flow on validation failure or cancel
|
|
169
|
+
- `ctx.namePath`: current field path in the form (array); use for nested `getFieldValue` / `setFieldValue` names
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# ctx.getModel()
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Returns a model instance (e.g. BlockModel, PageModel, ActionModel) from the current engine or view stack by its `uid`. Use 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 for the current execution context, use `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 another block’s model by known `uid`; read/write its `resource`, `form`, `setProps`, etc. |
|
|
12
|
+
| **RunJS inside popup** | Access a model on the page that opened the popup; pass `searchInPreviousEngines: true` |
|
|
13
|
+
| **Custom actions** | Find a form or sub-model in the settings panel across the view stack by `uid` |
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type
|
|
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` | Unique id of the target model (e.g. from config or creation) |
|
|
29
|
+
| `searchInPreviousEngines` | `boolean` | Optional, default `false`. When `true`, search up the view stack from the current engine to find models in parent views (e.g. the page that opened the popup) |
|
|
30
30
|
|
|
31
|
-
## Return
|
|
31
|
+
## Return value
|
|
32
32
|
|
|
33
|
-
- Returns the corresponding `FlowModel` subclass
|
|
33
|
+
- Returns the corresponding `FlowModel` subclass (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`)**: Search only in the **current engine** by `uid`. In popups or nested views, each view has its own engine; by default only the current view is searched.
|
|
39
|
+
- **`searchInPreviousEngines: true`**: Search from the current engine along the `previousEngine` chain; returns the first match. Use when RunJS in a popup needs to access a model on the page that opened it.
|
|
40
40
|
|
|
41
41
|
## Examples
|
|
42
42
|
|
|
@@ -49,17 +49,16 @@ if (block?.resource) {
|
|
|
49
49
|
}
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
### Access
|
|
52
|
+
### Access page model from inside popup
|
|
53
53
|
|
|
54
54
|
```ts
|
|
55
|
-
// Access a block on the page that opened the current popup
|
|
56
55
|
const pageBlock = ctx.getModel('page-block-uid', true);
|
|
57
56
|
if (pageBlock) {
|
|
58
57
|
pageBlock.rerender?.();
|
|
59
58
|
}
|
|
60
59
|
```
|
|
61
60
|
|
|
62
|
-
### Cross-model
|
|
61
|
+
### Cross-model update and rerender
|
|
63
62
|
|
|
64
63
|
```ts
|
|
65
64
|
const target = ctx.getModel('other-block-uid');
|
|
@@ -69,17 +68,17 @@ if (target) {
|
|
|
69
68
|
}
|
|
70
69
|
```
|
|
71
70
|
|
|
72
|
-
###
|
|
71
|
+
### Null check
|
|
73
72
|
|
|
74
73
|
```ts
|
|
75
74
|
const model = ctx.getModel(someUid);
|
|
76
75
|
if (!model) {
|
|
77
|
-
ctx.message.warning('Target model
|
|
76
|
+
ctx.message.warning('Target model not found');
|
|
78
77
|
return;
|
|
79
78
|
}
|
|
80
79
|
```
|
|
81
80
|
|
|
82
81
|
## Related
|
|
83
82
|
|
|
84
|
-
- [ctx.model](./model.md):
|
|
85
|
-
- [ctx.blockModel](./block-model.md):
|
|
83
|
+
- [ctx.model](./model.md): model for current execution context
|
|
84
|
+
- [ctx.blockModel](./block-model.md): parent block of current JS; often no need for `getModel`
|
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
# ctx.getValue()
|
|
2
2
|
|
|
3
|
-
In
|
|
3
|
+
In JSField, JSItem, and other editable field contexts, returns the current value of the field. Use with `ctx.setValue(v)` for two-way binding with the form.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSField** | Read user input or
|
|
10
|
-
| **JSItem** | Read
|
|
11
|
-
| **JSColumn** | Read
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **JSField** | Read user input or current form value in editable custom fields |
|
|
10
|
+
| **JSItem** | Read current cell value in table/sub-table editable items |
|
|
11
|
+
| **JSColumn** | Read row field value when rendering a column |
|
|
12
12
|
|
|
13
|
-
>
|
|
13
|
+
> Note: `ctx.getValue()` is only available in RunJS contexts with form binding; it does not exist in event flow, linkage, etc., where there is no field binding.
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
getValue<T = any>(): T | undefined;
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
- **
|
|
21
|
+
- **Returns**: Current field value; type depends on the field’s form item type. May be `undefined` if the field is not registered or not filled.
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## Value resolution
|
|
24
24
|
|
|
25
|
-
`ctx.getValue()`
|
|
25
|
+
`ctx.getValue()` resolves in this order:
|
|
26
26
|
|
|
27
|
-
1. **Form
|
|
28
|
-
2. **Fallback
|
|
27
|
+
1. **Form state**: Prefer current Ant Design Form state.
|
|
28
|
+
2. **Fallback**: If the field is not in the form, use the field’s initial value or props.
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
If the form is not yet rendered or the field is not registered, the result may be `undefined`.
|
|
31
31
|
|
|
32
32
|
## Examples
|
|
33
33
|
|
|
@@ -36,9 +36,9 @@ getValue<T = any>(): T | undefined;
|
|
|
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 something</span>);
|
|
40
40
|
} else {
|
|
41
|
-
ctx.render(<span>Current
|
|
41
|
+
ctx.render(<span>Current: {current}</span>);
|
|
42
42
|
}
|
|
43
43
|
```
|
|
44
44
|
|
|
@@ -47,7 +47,6 @@ if (current == null || current === '') {
|
|
|
47
47
|
```tsx
|
|
48
48
|
const { Input } = ctx.libs.antd;
|
|
49
49
|
|
|
50
|
-
// Read current value as default value
|
|
51
50
|
const defaultValue = ctx.getValue() ?? '';
|
|
52
51
|
|
|
53
52
|
ctx.render(
|
|
@@ -60,6 +59,6 @@ ctx.render(
|
|
|
60
59
|
|
|
61
60
|
## Related
|
|
62
61
|
|
|
63
|
-
- [ctx.setValue()](./set-value.md)
|
|
64
|
-
- [ctx.form](./form.md)
|
|
65
|
-
- `js-field:value-change
|
|
62
|
+
- [ctx.setValue()](./set-value.md): set current field value; use with getValue for two-way binding
|
|
63
|
+
- [ctx.form](./form.md): Ant Design Form instance for other fields
|
|
64
|
+
- `js-field:value-change`: container event when value changes from outside; use to update display
|