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
feat: threads path through field condition functions (#11528)
This PR updates the field `condition` function property to include a new
`path` argument.
The `path` arg provides the schema path of the field, including array
indices where applicable.
#### Changes:
- Added `path: (number | string)[]` in the Condition type.
- Updated relevant condition checks to ensure correct parameter usage.
All Description Functions receive the following arguments:
504
504
505
-
| Argument | Description |
505
+
| Argument | Description |
506
506
| --- | --- |
507
507
|**`t`**| The `t` function used to internationalize the Admin Panel. [More details](../configuration/i18n)|
508
508
@@ -512,11 +512,21 @@ All Description Functions receive the following arguments:
512
512
513
513
### Conditional Logic
514
514
515
-
You can show and hide fields based on what other fields are doing by utilizing conditional logic on a field by field basis. The `condition` property on a field's admin config accepts a function which takes three arguments:
515
+
You can show and hide fields based on what other fields are doing by utilizing conditional logic on a field by field basis. The `condition` property on a field's admin config accepts a function which takes the following arguments:
516
516
517
-
-`data` - the entire document's data that is currently being edited
518
-
-`siblingData` - only the fields that are direct siblings to the field with the condition
519
-
-`{ user }` - the final argument is an object containing the currently authenticated user
517
+
| Argument | Description |
518
+
| --- | --- |
519
+
|**`data`**| The entire document's data that is currently being edited. |
520
+
|**`siblingData`**| Only the fields that are direct siblings to the field with the condition. |
521
+
|**`ctx`**| An object containing additional information about the field’s location and user. |
522
+
523
+
The `ctx` object:
524
+
525
+
| Property | Description |
526
+
| --- | --- |
527
+
|**`blockData`**| The nearest parent block's data. If the field is not inside a block, this will be `undefined`. |
528
+
|**`path`**| The full path to the field in the schema, including array indexes. Useful for dynamic lookups. |
529
+
|**`user`**| The currently authenticated user object. |
520
530
521
531
The `condition` function should return a boolean that will control if the field should be displayed or not.
522
532
@@ -535,7 +545,7 @@ The `condition` function should return a boolean that will control if the field
535
545
type: 'text',
536
546
admin: {
537
547
// highlight-start
538
-
condition: (data, siblingData, { user }) => {
548
+
condition: (data, siblingData, { blockData, path, user }) => {
* The data of the nearest parent block. If the field is not within a block, `blockData` will be equal to `undefined`.
271
272
*/
272
273
blockData: Partial<TData>
274
+
/**
275
+
* The path of the field, e.g. ["group", "myArray", 1, "textField"]. The path is the schemaPath but with indexes and would be used in the context of field data, not field schemas.
0 commit comments