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
+28-1Lines changed: 28 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,7 @@ Features include:
12
12
- self-contained — rendered with plain HTML/CSS, so no dependance on external UI libraries
13
13
- search/filter data by key, value or custom function
14
14
- provide your own [custom component](#custom-nodes) to integrate specialised UI for certain data.
15
+
-[localisable](#localisation) UI
15
16
16
17
**[Explore the Demo](https://carlosnz.github.io/json-edit-react/)**
17
18
@@ -23,6 +24,7 @@ Features include:
23
24
-[Props overview](#props-overview)
24
25
-[Update functions](#update-functions)
25
26
-[OnChange function](#onchange-function)
27
+
-[OnError function](#onerror-function)
26
28
-[Copy function](#copy-function)
27
29
-[Filter functions](#filter-functions)
28
30
-[Examples](#examples-1)
@@ -96,6 +98,8 @@ The only *required* value is `data`.
96
98
|`onDelete`|`UpdateFunction`|| A function to run whenever a value is **deleted**. |
97
99
|`onAdd`|`UpdateFunction`|| A function to run whenever a new property is **added**. |
98
100
|`onChange`|`OnChangeFunction`|| A function to modify/constrain user input as they type -- see [OnChange functions](#onchange-function). |
101
+
|`onError`|`OnErrorFunction`|| A function to run whenever the component reports an error -- see [OnErrorFunction](#onerror-function). |
102
+
|`showErrorMessages`|`boolean `|`true`| Whether or not the component should display its own error messages (you'd probably only want to disable this if you provided your own `onError` function) |
99
103
|`enableClipboard`|`boolean\|CopyFunction`|`true`| Whether or not to enable the "Copy to clipboard" button in the UI. If a function is provided, `true` is assumed and this function will be run whenever an item is copied. |
100
104
|`indent`|`number`|`3`| Specify the amount of indentation for each level of nesting in the displayed data. |
101
105
|`collapse`|`boolean\|number\|FilterFunction`|`false`| Defines which nodes of the JSON tree will be displayed "opened" in the UI on load. If `boolean`, it'll be either all or none. A `number` specifies a nesting depth after which nodes will be closed. For more fine control a function can be provided — see [Filter functions](#filter-functions). |
@@ -169,6 +173,26 @@ The input object is similar to the Update function input, but with no `newData`
169
173
}
170
174
```
171
175
176
+
### OnError function
177
+
178
+
Normally, the component will display simple error messages whenever an error condition is detected (e.g. invalid JSON input, duplicate keys, or custom errors returned by the [`onUpdate` functions)](#update-functions)). However, you can provide your own `onError` callback in order to implement your own error UI, or run additional side effects. (In the former case, you'd probably want to disable the `showErrorMessages` prop, too.) The input to the callback is similar to the other callbacks:
179
+
180
+
```js
181
+
{
182
+
currentData, // data state before update
183
+
currentValue, // the current value of the property being updated
184
+
errorValue, // the erroneous value that failed to update the property
185
+
name, // name of the property being updated
186
+
path, // full path to the property being updated, as an array of property keys
code, // one of 'UPDATE_ERROR' | 'DELETE_ERROR' | 'ADD_ERROR' | 'INVALID_JSON' | 'KEY_EXISTS'
190
+
message // the (localised) error message that would be displayed
191
+
}
192
+
}
193
+
```
194
+
(An example of a custom Error UI can be seen in the [Demo](#https://carlosnz.github.io/json-edit-react/) with the "Custom Nodes" data set -- when you enter invalid JSON input a "Toast" notification is displayed instead of the normal component error message.)
195
+
172
196
### Copy function
173
197
174
198
A similar callback is executed whenever an item is copied to the clipboard (if passed to the `enableClipboard` prop), but with a different input parameter:
@@ -560,7 +584,7 @@ A few helper functions, components and types that might be useful in your own im
560
584
- `Theme`: a full [Theme](#themes--styles) object
561
585
- `ThemeInput`: input type for the `theme` prop
562
586
- `JsonEditorProps`: all input props for the Json Editor component
0 commit comments