You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13-2Lines changed: 13 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ npm i directus-extension-computed-interface
18
18
19
19
# Get Started
20
20
1. Go to **Settings**, create a new field with type string or number.
21
-
2. In the **Interface** panel, choose **Computed** interface. There are 5 options:
21
+
2. In the **Interface** panel, choose **Computed** interface. There are 8 options:
22
22
1.**Template**: Similar to M2M interface, determine how the field is calculated. Learn more about syntax in the next section.
23
23
2.**Field Mode**: Choose how the value is displayed.
24
24
-**null**: Default option. Show an input with the computed value but still allow manual editing.
@@ -27,6 +27,9 @@ npm i directus-extension-computed-interface
27
27
3.**Prefix**: a string to prefix the computed value.
28
28
4.**Suffix**: a string to suffix the computed value.
29
29
5.**Custom CSS**: an object for inline style binding. Only works with **Display Only** and **Read Only** mode. You can use this option to customize the appearance of the computed value such as font size, color, etc.
30
+
6.**Debug Mode**: Used for debugging the template. It will show an error message if the template is invalid. It will also log to console the result of each component of the template.
31
+
7.**Compute If Empty**: Compute the value if the field is empty. This is useful if you want a value to be computed once such as the created date or a unique ID.
32
+
8.**Initial Compute**: Compute the value when opening the form. This is useful if you want to compute a value based on the current date or other dynamic values.
30
33
31
34
# Syntax
32
35
@@ -171,13 +174,21 @@ Operator | Description
171
174
172
175
Operator | Description
173
176
--- | ---
174
-
`ASUM(a, b)` | Aggregated sum of O2M field. For example: calculate shopping cart total price with `ASUM(products, MULTIPLY(price, quantity))` where `products` is the O2M field in the shopping cart and `price` & `quantity` are 2 fields of `products`.
177
+
`ASUM(a, b)` | Aggregated sum of O2M field. For example: calculate shopping cart total price with `ASUM(products, MULTIPLY(price, quantity))`, where `products` is the O2M field in the shopping cart and `price` & `quantity` are 2 fields of `products`.
178
+
`AMIN(a, b)` | Aggregated min of O2M field.
179
+
`AMAX(a, b)` | Aggregated max of O2M field.
180
+
`AAVG(a, b)` | Aggregated average of O2M field.
181
+
`AMUL(a, b)` | Aggregated multiplication of O2M field.
182
+
`AAND(a, b)` | Aggregated logical AND of O2M field. Only return `true` if all values are `true`.
183
+
`AOR(a, b)` | Aggregated logical OR of O2M field. Only return `true` if at least one value is `true`.
184
+
`ACOUNT(a, b)` | Aggregated count of O2M field. Only count true values. For example: count the number of products that are in stock with `ACOUNT(products, GT(stock, 0))`, where `stock` is a field of `products`.
175
185
176
186
### Condition
177
187
178
188
Operator | Description
179
189
--- | ---
180
190
`IF(A, B, C)` | return `B` if `A` is `true`, otherwise `C`
191
+
`IFS(A1, B1, A2, B2, ..., An, Bn)` | return `Bi` if `Ai` is the first to be `true`, if none of `Ai` is `true`, return `null`
note: 'Used for debugging the template. It will show an error message if the template is invalid. It will also log to console the result of each component of the template.',
82
+
},
83
+
},
84
+
{
85
+
field: 'computeIfEmpty',
86
+
name: 'Compute If Empty',
87
+
type: 'boolean',
88
+
meta: {
89
+
width: 'full',
90
+
interface: 'boolean',
91
+
note: 'Compute the value if the field is empty. This is useful if you want a value to be computed once such as the created date or a unique ID.',
92
+
},
93
+
},
94
+
{
95
+
field: 'initialCompute',
96
+
name: 'Initial Compute',
97
+
type: 'boolean',
98
+
meta: {
99
+
width: 'full',
100
+
interface: 'boolean',
101
+
note: 'Compute the value when opening the form. This is useful if you want to compute a value based on the current date or other dynamic values.',
0 commit comments