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: content/docs/tutorial/dynamic-enum.mdx
+6-8
Original file line number
Diff line number
Diff line change
@@ -15,8 +15,7 @@ This approach allows you to build flexible and interactive forms that adapt to u
15
15
Imagine a form where users need to provide their location by selecting a country, a region and a city.
16
16
The options for countries and regions are fetched from an API.
17
17
The available regions depend on the selected country.
18
-
To address those requirements, we'll create custom renderers for the country and region.
19
-
The example is also implemented in the [react-seed](https://github.com/eclipsesource/jsonforms-react-seed) app.
18
+
To address those requirements, we'll create custom renderers for country and region.
20
19
21
20
<WithRegionRenderer />
22
21
@@ -26,7 +25,7 @@ The example is also implemented in the [react-seed](https://github.com/eclipseso
26
25
To begin, let's introduce the corresponding JSON schema.
27
26
We have created an object with properties for country, region, and city.
28
27
In our example, the schema also includes a property `x-url`, which specifies the entry point of the corresponding API.
29
-
Both `country` and `region` have a property `endpoint`, indicating the endpoint from which the data should be fetched.
28
+
Both `country` and `region` have a property `x-endpoint`, indicating the endpoint from which the data should be fetched.
30
29
Additionally, they have a field specifying which fields depend on the input.
31
30
In the case of the `country` field, the `region` and `city` fields depend on it and will get reset, if the value of the `country` changes.
32
31
The `city` field, in turn, is dependent on the `region` field.
@@ -84,7 +83,7 @@ const App = () =>{
84
83
85
84
### The Country Renderer
86
85
87
-
The core of the country renderer is a dropdown, we can reuse the MaterialEnumControl from the material-renderer set.
86
+
The core of the country renderer is a dropdown, therefore we can reuse the MaterialEnumControl from the React Material renderer set.
88
87
To reuse material renderers, the Unwrapped renderers must be used. (more information regarding reusing renderers can be seen [here](./custom-renderers#reusing-existing-controls))
89
88
90
89
```js
@@ -120,7 +119,7 @@ Changing the context's value will trigger a re-render of components that use it,
120
119
#### Accessing Schema Data
121
120
122
121
The `endpoint` and `dependent` fields can be obtained from the schema object provided to the custom renderer via JSON Forms.
123
-
Since these fields are not part of the standard JSON schema type in JSON Forms, we must add them to the schema´s interface and access them as follows:
122
+
Since these fields are not part of the standard JSON schema type in JSON Forms, we must add them to the schema's interface and access them as follows:
124
123
125
124
```js
126
125
type JsonSchemaWithDependenciesAndEndpoint = JsonSchema & {
@@ -142,7 +141,7 @@ export const Country = (
142
141
#### The Country Renderer
143
142
144
143
The country renderer uses the `APIContext` to query the API and fetch the available options.
145
-
We utilize the `useEffect` hook to reload new options, if API changes.
144
+
We utilize the `useEffect` hook to initialize the options.
146
145
While waiting for the API response, we set the available options to empty and display a loading spinner.
147
146
In the `handleChange` function, we set the new selected value and reset all dependent fields;
148
147
When changing the country, both the region and city will be reset to `undefined`.
0 commit comments