Skip to content

Commit b59da1a

Browse files
committed
Describe onNodeName in docs (see #617)
1 parent 8c74bc7 commit b59da1a

File tree

1 file changed

+52
-10
lines changed

1 file changed

+52
-10
lines changed

docs/api.md

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,21 @@ Constructs a new JSONEditor.
7171
The callback will only be triggered on changes made by the user, not in case of programmatic changes via the functions `set`, `setText`, `update`, or `updateText`.
7272
See also callback function `onChangeJSON(json)`.
7373

74-
- `{function} onEditable(node)`
74+
- `{function} onEditable({ field, value, path })`
7575

7676
Set a callback function to determine whether individual nodes are editable or read-only. Only applicable when option `mode` is `tree`, `text`, or `code`.
7777

78-
In case of mode `tree`, the callback is invoked as `editable(node)`, where `node` is an object `{field: string, value: string, path: string[]}`. The function must either return a boolean value to set both the nodes field and value editable or read-only, or return an object `{field: boolean, value: boolean}` to set set the read-only attribute for field and value individually.
78+
In case of mode `tree`, the callback is invoked as `editable(node)`, where the first parameter is an object:
79+
80+
```
81+
{
82+
field: string,
83+
value: string,
84+
path: string[]
85+
}
86+
```
87+
88+
The function must either return a boolean value to set both the nodes field and value editable or read-only, or return an object `{field: boolean, value: boolean}` to set set the read-only attribute for field and value individually.
7989

8090
In modes `text` and `code`, the callback is invoked as `editable(node)` where `node` is an empty object (no field, value, or path). In that case the function can return false to make the text or code editor completely read-only.
8191

@@ -89,6 +99,24 @@ Constructs a new JSONEditor.
8999
Set a callback function triggered right after the mode is changed by the user. Only applicable when
90100
the mode can be changed by the user (i.e. when option `modes` is set).
91101

102+
- `{function} onNodeName({ path, type, size })`
103+
104+
Customize the name of object and array nodes. By default the names are brackets with the number of childs inside,
105+
like `{5}` and `[32]`. The number inside can be customized. using `onNodeName`.
106+
107+
The first parameter is an object containing the following properties:
108+
109+
```
110+
{
111+
path: string[],
112+
type: 'object' | 'array',
113+
size: number
114+
}
115+
```
116+
117+
The `onNodeName` function should return a string containing the name for the node. If nothing is returned,
118+
the size (number of childs) will be displayed.
119+
92120
- `{function} onValidate(json)`
93121

94122
Set a callback function for custom validation. Available in all modes.
@@ -246,24 +274,24 @@ Constructs a new JSONEditor.
246274

247275
Adds status bar to the bottom of the editor - the status bar shows the cursor position and a count of the selected characters. True by default. Only applicable when `mode` is 'code' or 'text'.
248276

249-
- `{function} onTextSelectionChange`
277+
- `{function} onTextSelectionChange(start, end, text)`
250278

251279
Set a callback function triggered when a text is selected in the JSONEditor.
252280

253281
callback signature should be:
254282
```js
255283
/**
256-
* @param {{row:Number, column:Number}} startPos selection start position
257-
* @param {{row:Number, column:Number}} endPos selected end position
284+
* @param {{row:Number, column:Number}} start Selection start position
285+
* @param {{row:Number, column:Number}} end Selected end position
258286
* @param {String} text selected text
259287
*/
260-
function onTextSelectionChange(startPos, endPos, text) {
288+
function onTextSelectionChange(start, end, text) {
261289
...
262290
}
263291
```
264292
Only applicable when `mode` is 'code' or 'text'.
265293

266-
- `{function} onSelectionChange`
294+
- `{function} onSelectionChange(start, end)`
267295

268296
Set a callback function triggered when Nodes are selected in the JSONEditor.
269297

@@ -281,15 +309,29 @@ Constructs a new JSONEditor.
281309
```
282310
Only applicable when `mode` is 'tree'.
283311

284-
- `{function} onEvent`
312+
- `{function} onEvent({ field, path, value? }, event)`
285313

286314
Set a callback function that will be triggered when an event will occur in
287315
a JSON field or value.
288316

289317
In case of field event, node information will be
290-
`{field: string, path: {string|number}[]}`.
318+
319+
```
320+
{
321+
field: string,
322+
path: {string|number}[]
323+
}
324+
```
325+
291326
In case of value event, node information will be
292-
`{field: string, path: {string|number}[], value: string}`
327+
328+
```
329+
{
330+
field: string,
331+
path: {string|number}[],
332+
value: string
333+
}
334+
```
293335

294336
signature should be:
295337
```js

0 commit comments

Comments
 (0)