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: docs_headless/src/content/docs/ReferenceArrayInputBase.md
+40-1Lines changed: 40 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,7 +97,7 @@ dataProvider.getList('tags', {
97
97
});
98
98
```
99
99
100
-
`<ReferenceArrayInputBase>` handles the data fetching and provides the choices through a [`ChoicesContext`](./usechoicescontext). It's up to the child components to render the selection interface.
100
+
`<ReferenceArrayInputBase>` handles the data fetching and provides the choices through a [`ChoicesContext`](./useChoicesContext.md). It's up to the child components to render the selection interface.
101
101
102
102
You can tweak how `<ReferenceArrayInputBase>` fetches the possible values using the `page`, `perPage`, `sort`, and `filter` props.
103
103
@@ -108,6 +108,7 @@ You can tweak how `<ReferenceArrayInputBase>` fetches the possible values using
108
108
|`source`| Required |`string`| - | Name of the entity property to use for the input value |
109
109
|`reference`| Required |`string`| '' | Name of the reference resource, e.g. 'tags'. |
110
110
|`children`| Required |`ReactNode`| - | The actual selection component |
111
+
|`render`| Optional |`(context) => ReactNode`| - | Function that takes the choices context and renders the selection interface |
111
112
|`enableGetChoices`| Optional |`({q: string}) => boolean`|`() => true`| Function taking the `filterValues` and returning a boolean to enable the `getList` call. |
112
113
|`filter`| Optional |`Object`|`{}`| Permanent filters to use for getting the suggestion list |
113
114
|`offline`| Optional |`ReactNode`| - | What to render when there is no network connectivity when loading the record |
Alternatively, you can pass a `render` function prop instead of children. This function will receive the `ChoicesContext` as argument.
177
+
178
+
```jsx
179
+
exportconstMyReferenceArrayInput= () => (
180
+
<ReferenceArrayInputBase
181
+
source="tag_ids"
182
+
reference="tags"
183
+
render={({ choices, isLoading, error }) => {
184
+
if (isLoading) {
185
+
return<div>Loading...</div>;
186
+
}
187
+
188
+
if (error) {
189
+
return (
190
+
<div className="error">
191
+
{error.message}
192
+
</div>
193
+
);
194
+
}
195
+
196
+
return (
197
+
<select multiple>
198
+
{choices.map(choice=> (
199
+
<option key={choice.id} value={choice.id}>
200
+
{choice.name}
201
+
</option>
202
+
))}
203
+
</select>
204
+
);
205
+
}}
206
+
/>
207
+
);
208
+
```
209
+
210
+
The `render` function prop will take priority on `children` props if both are set.
211
+
173
212
## `enableGetChoices`
174
213
175
214
You can make the `getList()` call lazy by using the `enableGetChoices` prop. This prop should be a function that receives the `filterValues` as parameter and return a boolean. This can be useful when using a search input on a resource with a lot of data. The following example only starts fetching the options when the query has at least 2 characters:
`<ReferenceInputBase>` handles the data fetching and provides the choices through a [`ChoicesContext`](./usechoicescontext). It's up to the child components to render the selection interface.
90
+
`<ReferenceInputBase>` handles the data fetching and provides the choices through a [`ChoicesContext`](./useChoicesContext.md). It's up to the child components to render the selection interface.
91
91
92
92
You can tweak how `<ReferenceInputBase>` fetches the possible values using the `page`, `perPage`, `sort`, and `filter` props.
93
93
@@ -115,7 +115,7 @@ You can access the choices context using the `useChoicesContext` hook.
Copy file name to clipboardExpand all lines: docs_headless/src/content/docs/useChoicesContext.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ title: "useChoicesContext"
4
4
5
5
The [`<ReferenceInputBase>`](./ReferenceInputBase.md) and [`<ReferenceArrayInputBase>`](./ReferenceArrayInputBase.md) components create a `ChoicesContext` to store the choices, as well as filters, pagination, sort state, and callbacks to update them.
6
6
7
-
The `ChoicesContext` is very similar to the [`ListContext`](./uselistcontext) with the exception that it does not return a `data` property but 3 choices related properties:
7
+
The `ChoicesContext` is very similar to the [`ListContext`](./useListContext.md) with the exception that it does not return a `data` property but 3 choices related properties:
8
8
9
9
-`availableChoices`: The choices that are not selected but match the parameters (sorting, pagination and filters)
0 commit comments