@wirenboard/json-editor 2.5.3-wb13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env-dist +2 -0
- package/.eslintrc +7 -0
- package/.gitattributes +1 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +9 -0
- package/.github/issue_template +25 -0
- package/.github/workflows/build.yml +58 -0
- package/.travis.yml +70 -0
- package/CHANGELOG.md +915 -0
- package/CONTRIBUTING.md +92 -0
- package/LICENSE +20 -0
- package/Makefile +26 -0
- package/README.md +1646 -0
- package/README_ADDON.md +573 -0
- package/UPGRADING.md +46 -0
- package/build/CssToJson.js +55 -0
- package/codecept.conf.js +35 -0
- package/config/.eslintrc +7 -0
- package/config/codeceptjs_helpers.js +139 -0
- package/config/helpers.js +10 -0
- package/config/karma.conf.js +93 -0
- package/config/readme.md +31 -0
- package/config/webpack.common.js +75 -0
- package/config/webpack.dev.js +15 -0
- package/config/webpack.nonmin.js +19 -0
- package/config/webpack.prod.js +25 -0
- package/dist/jsoneditor.js +14 -0
- package/dist/nonmin/jsoneditor.js +29097 -0
- package/dist/nonmin/jsoneditor.js.map +1 -0
- package/docs/ace_editor.html +56 -0
- package/docs/advanced.html +136 -0
- package/docs/basic.html +63 -0
- package/docs/basic_person.json +26 -0
- package/docs/choices.html +86 -0
- package/docs/cleave.html +132 -0
- package/docs/colorpicker.html +194 -0
- package/docs/css_integration.html +135 -0
- package/docs/datetime.html +305 -0
- package/docs/describedby.html +161 -0
- package/docs/enumsource.html +67 -0
- package/docs/images/categoriesDemo.png +0 -0
- package/docs/images/inheritance_tree.png +0 -0
- package/docs/images/jsoneditor.png +0 -0
- package/docs/imask.html +192 -0
- package/docs/index.html +579 -0
- package/docs/materialize_css.html +164 -0
- package/docs/meta_schema.json +705 -0
- package/docs/multiple_upload_base64.html +65 -0
- package/docs/person.json +73 -0
- package/docs/polyfills/assign.js +29 -0
- package/docs/radio.html +156 -0
- package/docs/recursive.html +170 -0
- package/docs/select2.html +99 -0
- package/docs/selectize.html +100 -0
- package/docs/signature.html +42 -0
- package/docs/starrating.html +137 -0
- package/docs/upload.html +131 -0
- package/docs/uuid.html +70 -0
- package/docs/wysiwyg.html +56 -0
- package/jasmine.json +11 -0
- package/json-editor-json-editor-2.5.3-wb13.tgz +0 -0
- package/package.json +100 -0
- package/release-notes.md +88 -0
- package/src/core.js +412 -0
- package/src/defaults.js +402 -0
- package/src/editor.js +707 -0
- package/src/editors/ace.js +89 -0
- package/src/editors/array/choices.js +103 -0
- package/src/editors/array/select2.js +110 -0
- package/src/editors/array/selectize.js +103 -0
- package/src/editors/array.css +9 -0
- package/src/editors/array.css.js +3 -0
- package/src/editors/array.js +818 -0
- package/src/editors/autocomplete.js +58 -0
- package/src/editors/base64.js +157 -0
- package/src/editors/button.js +97 -0
- package/src/editors/checkbox.js +95 -0
- package/src/editors/choices.css +3 -0
- package/src/editors/choices.css.js +3 -0
- package/src/editors/choices.js +69 -0
- package/src/editors/colorpicker.js +103 -0
- package/src/editors/datetime.js +141 -0
- package/src/editors/describedby.js +188 -0
- package/src/editors/enum.js +136 -0
- package/src/editors/hidden.js +127 -0
- package/src/editors/index.js +81 -0
- package/src/editors/info.js +20 -0
- package/src/editors/integer.js +19 -0
- package/src/editors/ip.js +36 -0
- package/src/editors/jodit.js +64 -0
- package/src/editors/multiple.js +409 -0
- package/src/editors/multiselect.js +218 -0
- package/src/editors/null.js +18 -0
- package/src/editors/number.js +51 -0
- package/src/editors/object.css +41 -0
- package/src/editors/object.css.js +3 -0
- package/src/editors/object.js +1290 -0
- package/src/editors/radio.js +111 -0
- package/src/editors/sceditor.js +72 -0
- package/src/editors/select.js +370 -0
- package/src/editors/select2.js +110 -0
- package/src/editors/selectize.js +112 -0
- package/src/editors/signature.js +113 -0
- package/src/editors/simplemde.js +100 -0
- package/src/editors/starrating.css +52 -0
- package/src/editors/starrating.css.js +3 -0
- package/src/editors/starrating.js +135 -0
- package/src/editors/stepper.js +27 -0
- package/src/editors/string.js +372 -0
- package/src/editors/table.js +516 -0
- package/src/editors/upload.js +321 -0
- package/src/editors/uuid.js +56 -0
- package/src/iconlib.js +24 -0
- package/src/iconlibs/bootstrap2.js +28 -0
- package/src/iconlibs/bootstrap3.js +28 -0
- package/src/iconlibs/fontawesome3.js +28 -0
- package/src/iconlibs/fontawesome4.js +28 -0
- package/src/iconlibs/fontawesome5.js +28 -0
- package/src/iconlibs/foundation2.js +24 -0
- package/src/iconlibs/foundation3.js +28 -0
- package/src/iconlibs/index.js +25 -0
- package/src/iconlibs/jqueryui.js +28 -0
- package/src/iconlibs/materialicons.js +49 -0
- package/src/iconlibs/openiconic.js +28 -0
- package/src/iconlibs/spectre.js +28 -0
- package/src/resolvers.js +128 -0
- package/src/schemaloader.js +408 -0
- package/src/style.css +150 -0
- package/src/style.css.js +3 -0
- package/src/templates/default.js +52 -0
- package/src/templates/ejs.js +13 -0
- package/src/templates/handlebars.js +1 -0
- package/src/templates/hogan.js +10 -0
- package/src/templates/index.js +21 -0
- package/src/templates/lodash.js +9 -0
- package/src/templates/markup.js +9 -0
- package/src/templates/mustache.js +9 -0
- package/src/templates/swig.js +1 -0
- package/src/templates/underscore.js +9 -0
- package/src/theme.js +659 -0
- package/src/themes/barebones.css +35 -0
- package/src/themes/barebones.css.js +3 -0
- package/src/themes/barebones.js +28 -0
- package/src/themes/bootstrap2.js +319 -0
- package/src/themes/bootstrap3.css +0 -0
- package/src/themes/bootstrap3.css.js +3 -0
- package/src/themes/bootstrap3.js +315 -0
- package/src/themes/bootstrap4.css +89 -0
- package/src/themes/bootstrap4.css.js +3 -0
- package/src/themes/bootstrap4.js +690 -0
- package/src/themes/bootstrap5.css.js +3 -0
- package/src/themes/foundation.js +569 -0
- package/src/themes/html.css +60 -0
- package/src/themes/html.css.js +3 -0
- package/src/themes/html.js +71 -0
- package/src/themes/index.js +28 -0
- package/src/themes/jqueryui.js +198 -0
- package/src/themes/materialize.js +426 -0
- package/src/themes/spectre.css +208 -0
- package/src/themes/spectre.css.js +3 -0
- package/src/themes/spectre.js +406 -0
- package/src/themes/tailwind.css +249 -0
- package/src/themes/tailwind.css.js +3 -0
- package/src/themes/tailwind.js +443 -0
- package/src/utilities.js +138 -0
- package/src/validator.js +877 -0
- package/src/validators/ip-validator.js +51 -0
- package/tests/Dockerfile +3 -0
- package/tests/README.md +48 -0
- package/tests/codeceptjs/codecept.json +42 -0
- package/tests/codeceptjs/constrains/if-then-else_test.js +143 -0
- package/tests/codeceptjs/core_test.js +217 -0
- package/tests/codeceptjs/editors/advanced_test.js +13 -0
- package/tests/codeceptjs/editors/array_any_of_test.js +50 -0
- package/tests/codeceptjs/editors/array_test.js +900 -0
- package/tests/codeceptjs/editors/button_test.js +35 -0
- package/tests/codeceptjs/editors/checkbox_test.js +21 -0
- package/tests/codeceptjs/editors/colorpicker_test.js +27 -0
- package/tests/codeceptjs/editors/datetime_test.js +33 -0
- package/tests/codeceptjs/editors/inheritance_test.js +11 -0
- package/tests/codeceptjs/editors/integer_test.js +84 -0
- package/tests/codeceptjs/editors/issues/issue-gh-812_test.js +32 -0
- package/tests/codeceptjs/editors/jodit_test.js +24 -0
- package/tests/codeceptjs/editors/multiselect_test.js +8 -0
- package/tests/codeceptjs/editors/number_test.js +82 -0
- package/tests/codeceptjs/editors/object_test.js +204 -0
- package/tests/codeceptjs/editors/option-no_default_values_test.js +42 -0
- package/tests/codeceptjs/editors/programmatic-changes_test.js +20 -0
- package/tests/codeceptjs/editors/radio_test.js +10 -0
- package/tests/codeceptjs/editors/rating_test.js +13 -0
- package/tests/codeceptjs/editors/select_test.js +22 -0
- package/tests/codeceptjs/editors/stepper_test.js +27 -0
- package/tests/codeceptjs/editors/string_test.js +118 -0
- package/tests/codeceptjs/editors/table-confirm-delete_test.js +67 -0
- package/tests/codeceptjs/editors/tabs_test.js +14 -0
- package/tests/codeceptjs/editors/uuid_test.js +21 -0
- package/tests/codeceptjs/editors/validation_test.js +14 -0
- package/tests/codeceptjs/meta-schema_test.js +17 -0
- package/tests/codeceptjs/schemaloader_test.js +13 -0
- package/tests/codeceptjs/steps.d.ts +13 -0
- package/tests/codeceptjs/steps_file.js +12 -0
- package/tests/codeceptjs/themes_test.js +519 -0
- package/tests/docker-compose.yml +34 -0
- package/tests/fixtures/basic_person.json +26 -0
- package/tests/fixtures/nested_object.json +26 -0
- package/tests/fixtures/person.json +55 -0
- package/tests/fixtures/recursive.json +8 -0
- package/tests/fixtures/some_types.json +32 -0
- package/tests/fixtures/string.json +3 -0
- package/tests/fixtures/validation.json +1140 -0
- package/tests/pages/_demo.html +475 -0
- package/tests/pages/advanced.html +137 -0
- package/tests/pages/anyof.html +80 -0
- package/tests/pages/array-anyof.html +142 -0
- package/tests/pages/array-checkboxes.html +41 -0
- package/tests/pages/array-choices.html +45 -0
- package/tests/pages/array-integers.html +37 -0
- package/tests/pages/array-move-events.html +61 -0
- package/tests/pages/array-multiselects.html +42 -0
- package/tests/pages/array-nested-arrays.html +40 -0
- package/tests/pages/array-numbers.html +37 -0
- package/tests/pages/array-objects.html +42 -0
- package/tests/pages/array-ratings.html +40 -0
- package/tests/pages/array-selectize.html +51 -0
- package/tests/pages/array-selects.html +36 -0
- package/tests/pages/array-strings.html +36 -0
- package/tests/pages/array.html +42 -0
- package/tests/pages/assets/pages.css +130 -0
- package/tests/pages/button-callbacks.html +77 -0
- package/tests/pages/checkbox-labels.html +114 -0
- package/tests/pages/colorpicker-no-3rd-party.html +43 -0
- package/tests/pages/colorpicker-use-vanilla-picker.html +50 -0
- package/tests/pages/core.html +118 -0
- package/tests/pages/datetime.html +76 -0
- package/tests/pages/form-name.html +108 -0
- package/tests/pages/grid-strict.html +311 -0
- package/tests/pages/grid.html +284 -0
- package/tests/pages/if-then-else-allOf.html +117 -0
- package/tests/pages/inheritance.html +76 -0
- package/tests/pages/integer.html +68 -0
- package/tests/pages/issues/_template.html +50 -0
- package/tests/pages/issues/issue-gh-812.html +110 -0
- package/tests/pages/issues/issue-gh-823-meta-schema.html +35 -0
- package/tests/pages/issues/issue-gh-848.html +81 -0
- package/tests/pages/meta_schema.json +705 -0
- package/tests/pages/number.html +89 -0
- package/tests/pages/object-no-additional-properties.html +65 -0
- package/tests/pages/object-no-duplicated-id.html +68 -0
- package/tests/pages/object-required-properties.html +236 -0
- package/tests/pages/object-with-dependencies-array.html +46 -0
- package/tests/pages/object-with-dependencies.html +60 -0
- package/tests/pages/object.html +79 -0
- package/tests/pages/oneof.html +103 -0
- package/tests/pages/option-no_default_values.html +58 -0
- package/tests/pages/programmatic-changes.html +120 -0
- package/tests/pages/read-only.html +105 -0
- package/tests/pages/select.html +41 -0
- package/tests/pages/stepper.html +59 -0
- package/tests/pages/string-ace-editor.html +52 -0
- package/tests/pages/string-cleave.html +46 -0
- package/tests/pages/string-custom-attributes.html +62 -0
- package/tests/pages/string-formats.html +52 -0
- package/tests/pages/string-formats2.html +57 -0
- package/tests/pages/string-jodit-editor.html +49 -0
- package/tests/pages/string-sceditor.html +62 -0
- package/tests/pages/table-move-events.html +56 -0
- package/tests/pages/table.html +46 -0
- package/tests/pages/tabs.html +131 -0
- package/tests/pages/themes.html +527 -0
- package/tests/pages/translate-property.html +247 -0
- package/tests/pages/urn.html +93 -0
- package/tests/pages/uuid.html +72 -0
- package/tests/pages/validation.html +99 -0
- package/tests/unit/.eslintrc +8 -0
- package/tests/unit/core.spec.js +309 -0
- package/tests/unit/defaults.spec.js +40 -0
- package/tests/unit/editor.spec.js +160 -0
- package/tests/unit/editors/array.spec.js +86 -0
- package/tests/unit/editors/object.spec.js +79 -0
- package/tests/unit/editors/table.spec.js +91 -0
- package/tests/unit/readme.md +35 -0
- package/tests/unit/schemaloader.spec.js +498 -0
- package/tests/unit/validator.spec.js +94 -0
- package/tests/unit/validators/ip-validator.spec.js +62 -0
package/README.md
ADDED
|
@@ -0,0 +1,1646 @@
|
|
|
1
|
+
JSON Editor
|
|
2
|
+
===========
|
|
3
|
+
|
|
4
|
+
[](https://github.com/json-editor/json-editor/actions)
|
|
5
|
+
|
|
6
|
+
Fork of the inactive [jdorn/json-editor](https://github.com/jdorn/json-editor) using the updated fork [json-editor/json-editor](https://github.com/json-editor/json-editor).
|
|
7
|
+
Some pull requests added from the original repo.
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
JSON Editor takes a JSON Schema and uses it to generate an HTML form.
|
|
12
|
+
It has full support for JSON Schema version 3 and 4 and can integrate with several popular CSS frameworks (bootstrap, spectre, tailwind).
|
|
13
|
+
|
|
14
|
+
### Online Demo
|
|
15
|
+
|
|
16
|
+
Check out an interactive demo: https://json-editor.github.io/json-editor/
|
|
17
|
+
|
|
18
|
+
Or the JSON-Editor Interactive Playground: https://pmk65.github.io/jedemov2/dist/demo.html
|
|
19
|
+
|
|
20
|
+
Install
|
|
21
|
+
-----------------
|
|
22
|
+
|
|
23
|
+
Install package
|
|
24
|
+
|
|
25
|
+
npm install @json-editor/json-editor
|
|
26
|
+
|
|
27
|
+
Using a CDN
|
|
28
|
+
|
|
29
|
+
<script src="https://cdn.jsdelivr.net/npm/@json-editor/json-editor@latest/dist/jsoneditor.min.js"></script>
|
|
30
|
+
|
|
31
|
+
You can also access older releases from CDN, using the landing page: https://www.jsdelivr.com/package/npm/@json-editor/json-editor
|
|
32
|
+
|
|
33
|
+
For local usage download the [production version](https://cdn.jsdelivr.net/npm/@json-editor/json-editor@latest/dist/jsoneditor.js) or the [development version](https://cdn.jsdelivr.net/npm/@json-editor/json-editor@latest/dist/nonmin/jsoneditor.js)
|
|
34
|
+
|
|
35
|
+
Requirements
|
|
36
|
+
-----------------
|
|
37
|
+
|
|
38
|
+
JSON Editor has no dependencies. It only needs a modern browser (tested in Chrome and Firefox).
|
|
39
|
+
|
|
40
|
+
### Optional Requirements
|
|
41
|
+
|
|
42
|
+
The following are not required, but can improve the style and usability of JSON Editor when present.
|
|
43
|
+
|
|
44
|
+
* A compatible JS template engine (Mustache, Underscore, Hogan, Handlebars, Lodash, Swig, Markup, or EJS)
|
|
45
|
+
* A compatible CSS framework for styling (Spectre, Tailwind, Bootstrap4)
|
|
46
|
+
* A compatible icon library (Spectre, jQueryUI, Font Awesome 3/4/5)
|
|
47
|
+
* [SCEditor](http://www.sceditor.com/) for WYSIWYG editing of HTML or BBCode content
|
|
48
|
+
* [SimpleMDE](https://simplemde.com/) for editing of Markdown content
|
|
49
|
+
* [Ace Editor](http://ace.c9.io/) for editing code
|
|
50
|
+
* [Jodit](https://xdsoft.net/jodit/) Open Source WYSIWYG editor
|
|
51
|
+
* [Autocomplete](https://autocomplete.trevoreyre.com/#/javascript-component) Accessible autocomplete component
|
|
52
|
+
* [Choices](https://github.com/jshjohnson/Choices) for nicer Select & Array boxes
|
|
53
|
+
* [Select2](http://ivaynberg.github.io/select2/) for nicer Select boxes
|
|
54
|
+
* [Selectize](https://selectize.github.io/selectize.js/) for nicer Select & Array boxes
|
|
55
|
+
* [Flatpickr](https://flatpickr.js.org/) lightweight and powerful datetime picker
|
|
56
|
+
* [Signature Pad](https://github.com/szimek/signature_pad) HTML5 canvas based smooth signature drawing
|
|
57
|
+
* [Vanilla Picker](https://vanilla-picker.js.org/) A simple, easy to use vanilla JS color picker with alpha selection
|
|
58
|
+
* [Cleave.js](https://github.com/nosir/cleave.js) for formatting your **<input/>** content while you are typing
|
|
59
|
+
* [IMask.js](https://imask.js.org/) vanilla javascript input mask
|
|
60
|
+
* [math.js](http://mathjs.org/) for more accurate floating point math (multipleOf, divisibleBy, etc.)
|
|
61
|
+
* [DOMPurify](https://github.com/cure53/DOMPurify) DOM-only, super-fast, uber-tolerant XSS sanitizer. (If you want to use HTML format in titles/headers and descriptions.)
|
|
62
|
+
|
|
63
|
+
Usage
|
|
64
|
+
--------------
|
|
65
|
+
|
|
66
|
+
If you learn best by example, check these out:
|
|
67
|
+
|
|
68
|
+
* Basic Usage Example - https://json-editor.github.io/json-editor/basic.html
|
|
69
|
+
* ACE Editor Example - https://json-editor.github.io/json-editor/ace_editor.html
|
|
70
|
+
* Advanced Usage Example - https://json-editor.github.io/json-editor/advanced.html
|
|
71
|
+
* CSS Integration Example - https://json-editor.github.io/json-editor/css_integration.html
|
|
72
|
+
* Base64 Editor Example (Muiltple Upload) - https://json-editor.github.io/json-editor/multiple_upload_base64.html
|
|
73
|
+
* Choices Editor Example - https://json-editor.github.io/json-editor/choices.html
|
|
74
|
+
* Cleave.js Editor Example - https://json-editor.github.io/json-editor/cleave.html
|
|
75
|
+
* Colorpicker Editor Example - https://json-editor.github.io/json-editor/colorpicker.html
|
|
76
|
+
* Datetime Editor Example - https://json-editor.github.io/json-editor/datetime.html
|
|
77
|
+
* DescribedBy Hyperlink Editor Example - https://json-editor.github.io/json-editor/describedby.html
|
|
78
|
+
* iMask.js Editor Example - https://json-editor.github.io/json-editor/imask.html
|
|
79
|
+
* Radio Button JSON Editor Example - https://json-editor.github.io/json-editor/radio.html
|
|
80
|
+
* Recursive JSON Editor Example - https://json-editor.github.io/json-editor/recursive.html
|
|
81
|
+
* Select2 Editor Example - https://json-editor.github.io/json-editor/select2.html
|
|
82
|
+
* Selectize Editor Example - https://json-editor.github.io/json-editor/selectize.html
|
|
83
|
+
* Signature Pad Editor Example - https://json-editor.github.io/json-editor/signature.html
|
|
84
|
+
* Star Rating Editor Example - https://json-editor.github.io/json-editor/starrating.html
|
|
85
|
+
* Upload Editor Example - https://json-editor.github.io/json-editor/upload.html
|
|
86
|
+
* WYSIWYG Editor Example - https://json-editor.github.io/json-editor/wysiwyg.html
|
|
87
|
+
|
|
88
|
+
More examples can be found at the [JSON-Editor Interactive Playground](https://pmk65.github.io/jedemov2/dist/demo.html)
|
|
89
|
+
|
|
90
|
+
The rest of this README contains detailed documentation about every aspect of JSON Editor. For more [under-the-hood documentation](https://github.com/json-editor/json-editor/wiki), check the wiki.
|
|
91
|
+
|
|
92
|
+
### Initialize
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
const element = document.getElementById('editor_holder');
|
|
96
|
+
|
|
97
|
+
const editor = new JSONEditor(element, options);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### Options
|
|
101
|
+
|
|
102
|
+
Options can be set globally or on a per-instance basis during instantiation.
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
// Set an option globally
|
|
106
|
+
JSONEditor.defaults.options.theme = 'bootstrap4';
|
|
107
|
+
|
|
108
|
+
// Set an option during instantiation
|
|
109
|
+
const editor = new JSONEditor(element, {
|
|
110
|
+
//...
|
|
111
|
+
theme: 'bootstrap4'
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Here are all the available options:
|
|
116
|
+
|
|
117
|
+
<table>
|
|
118
|
+
<thead>
|
|
119
|
+
<tr>
|
|
120
|
+
<th>Option</th>
|
|
121
|
+
<th>Description</th>
|
|
122
|
+
<th>Default Value</th>
|
|
123
|
+
</tr>
|
|
124
|
+
</thead>
|
|
125
|
+
<tbody>
|
|
126
|
+
<tr>
|
|
127
|
+
<td>ajax</td>
|
|
128
|
+
<td>If <code>true</code>, JSON Editor will load external URLs in <code>$ref</code> via ajax.</td>
|
|
129
|
+
<td><code>false</code></td>
|
|
130
|
+
</tr>
|
|
131
|
+
<tr>
|
|
132
|
+
<td>ajaxBase</td>
|
|
133
|
+
<td>Allows schema references to work either with or without cors; set to protocol://host:port when api is served by different host.</td>
|
|
134
|
+
<td><code></code></td>
|
|
135
|
+
</tr>
|
|
136
|
+
<tr>
|
|
137
|
+
<td>ajaxCredentials</td>
|
|
138
|
+
<td>If <code>true</code>, JSON Editor will make ajax call with [credentials](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials).</td>
|
|
139
|
+
<td><code>false</code></td>
|
|
140
|
+
</tr>
|
|
141
|
+
<tr>
|
|
142
|
+
<td>compact</td>
|
|
143
|
+
<td>If <code>true</code>, the label will not be displayed/added.</td>
|
|
144
|
+
<td><code>false</code></td>
|
|
145
|
+
</tr>
|
|
146
|
+
<tr>
|
|
147
|
+
<td>disable_array_add</td>
|
|
148
|
+
<td>If <code>true</code>, remove all "add row" buttons from arrays.</td>
|
|
149
|
+
<td><code>false</code></td>
|
|
150
|
+
</tr>
|
|
151
|
+
<tr>
|
|
152
|
+
<td>disable_array_delete</td>
|
|
153
|
+
<td>If <code>true</code>, remove all "delete row" buttons from arrays.</td>
|
|
154
|
+
<td><code>false</code></td>
|
|
155
|
+
</tr>
|
|
156
|
+
<tr>
|
|
157
|
+
<td>disable_array_delete_all_rows</td>
|
|
158
|
+
<td>If <code>true</code>, remove all "delete all rows" buttons from arrays.</td>
|
|
159
|
+
<td><code>false</code></td>
|
|
160
|
+
</tr>
|
|
161
|
+
<tr>
|
|
162
|
+
<td>disable_array_delete_last_row</td>
|
|
163
|
+
<td>If <code>true</code>, remove all "delete last row" buttons from arrays.</td>
|
|
164
|
+
<td><code>false</code></td>
|
|
165
|
+
</tr>
|
|
166
|
+
<tr>
|
|
167
|
+
<td>disable_array_reorder</td>
|
|
168
|
+
<td>If <code>true</code>, remove all "move up" and "move down" buttons from arrays.</td>
|
|
169
|
+
<td><code>false</code></td>
|
|
170
|
+
</tr>
|
|
171
|
+
<tr>
|
|
172
|
+
<td>enable_array_copy</td>
|
|
173
|
+
<td>If <code>true</code>, add copy buttons to arrays.</td>
|
|
174
|
+
<td><code>false</code></td>
|
|
175
|
+
</tr>
|
|
176
|
+
<tr>
|
|
177
|
+
<td>disable_collapse</td>
|
|
178
|
+
<td>If <code>true</code>, remove all collapse buttons from objects and arrays.</td>
|
|
179
|
+
<td><code>false</code></td>
|
|
180
|
+
</tr>
|
|
181
|
+
<tr>
|
|
182
|
+
<td>disable_edit_json</td>
|
|
183
|
+
<td>If <code>true</code>, remove all Edit JSON buttons from objects.</td>
|
|
184
|
+
<td><code>false</code></td>
|
|
185
|
+
</tr>
|
|
186
|
+
<tr>
|
|
187
|
+
<td>disable_properties</td>
|
|
188
|
+
<td>If <code>true</code>, remove all Edit Properties buttons from objects.</td>
|
|
189
|
+
<td><code>false</code></td>
|
|
190
|
+
</tr>
|
|
191
|
+
<tr>
|
|
192
|
+
<tr>
|
|
193
|
+
<td>array_controls_top</td>
|
|
194
|
+
<td>If <code>true</code>, array controls (add, delete etc) will be displayed at top of list.</td>
|
|
195
|
+
<td><code>false</code></td>
|
|
196
|
+
</tr>
|
|
197
|
+
<tr>
|
|
198
|
+
<td>form_name_root</td>
|
|
199
|
+
<td>The first part of the `name` attribute of form inputs in the editor. An full example name is `root[person][name]` where "root" is the form_name_root.</td>
|
|
200
|
+
<td>root</td>
|
|
201
|
+
</tr>
|
|
202
|
+
<tr>
|
|
203
|
+
<td>iconlib</td>
|
|
204
|
+
<td>The icon library to use for the editor. See the <strong>CSS Integration</strong> section below for more info.</td>
|
|
205
|
+
<td><code>null</code></td>
|
|
206
|
+
</tr>
|
|
207
|
+
<tr>
|
|
208
|
+
<td>remove_button_labels</td>
|
|
209
|
+
<td>Display only icons in buttons. This works only if iconlib is set.</td>
|
|
210
|
+
<td><code>false</code></td>
|
|
211
|
+
</tr>
|
|
212
|
+
<tr>
|
|
213
|
+
<td>no_additional_properties</td>
|
|
214
|
+
<td>If <code>true</code>, objects can only contain properties defined with the <code>properties</code> keyword unless the property <code>additionalProperties: true</code> is specified in the object schema</td>
|
|
215
|
+
<td><code>false</code></td>
|
|
216
|
+
</tr>
|
|
217
|
+
<tr>
|
|
218
|
+
<td>refs</td>
|
|
219
|
+
<td>An object containing schema definitions for URLs. Allows you to pre-define external schemas.</td>
|
|
220
|
+
<td><code>{}</code></td>
|
|
221
|
+
</tr>
|
|
222
|
+
<tr>
|
|
223
|
+
<td>required_by_default</td>
|
|
224
|
+
<td>If <code>true</code>, all schemas that don't explicitly set the <code>required</code> property will be required.</td>
|
|
225
|
+
<td><code>false</code></td>
|
|
226
|
+
</tr>
|
|
227
|
+
<tr>
|
|
228
|
+
<td>keep_oneof_values</td>
|
|
229
|
+
<td>If <code>true</code>, makes oneOf copy properties over when switching.</td>
|
|
230
|
+
<td><code>true</code></td>
|
|
231
|
+
</tr>
|
|
232
|
+
<tr>
|
|
233
|
+
<td>schema</td>
|
|
234
|
+
<td>A valid JSON Schema to use for the editor. Version 3 and Version 4 of the draft specification are supported.</td>
|
|
235
|
+
<td><code>{}</code></td>
|
|
236
|
+
</tr>
|
|
237
|
+
<tr>
|
|
238
|
+
<td>show_errors</td>
|
|
239
|
+
<td>When to show validation errors in the UI. Valid values are <code>interaction</code>, <code>change</code>, <code>always</code>, and <code>never</code>.</td>
|
|
240
|
+
<td><code>"interaction"</code></td>
|
|
241
|
+
</tr>
|
|
242
|
+
<tr>
|
|
243
|
+
<td>startval</td>
|
|
244
|
+
<td>Seed the editor with an initial value. This should be valid against the editor's schema.</td>
|
|
245
|
+
<td><code>null</code></td>
|
|
246
|
+
</tr>
|
|
247
|
+
<tr>
|
|
248
|
+
<td>template</td>
|
|
249
|
+
<td>The JS template engine to use. See the <strong>Templates and Variables</strong> section below for more info.</td>
|
|
250
|
+
<td><code>default</code></td>
|
|
251
|
+
</tr>
|
|
252
|
+
<tr>
|
|
253
|
+
<td>theme</td>
|
|
254
|
+
<td>The CSS theme to use. See the <strong>CSS Integration</strong> section below for more info.</td>
|
|
255
|
+
<td><code>html</code></td>
|
|
256
|
+
</tr>
|
|
257
|
+
<tr>
|
|
258
|
+
<td>display_required_only</td>
|
|
259
|
+
<td>If <code>true</code>, only required properties will be included by default.</td>
|
|
260
|
+
<td><code>false</code></td>
|
|
261
|
+
</tr>
|
|
262
|
+
<tr>
|
|
263
|
+
<td>show_opt_in</td>
|
|
264
|
+
<td>If <code>true</code>, NON required properties will have an extra toggable checkbox near the title that determines if the value must be included or not in the editor´s value</td>
|
|
265
|
+
<td><code>false</code></td>
|
|
266
|
+
</tr>
|
|
267
|
+
<tr>
|
|
268
|
+
<td>prompt_before_delete</td>
|
|
269
|
+
<td>If <code>true</code>, displays a dialog box with a confirmation message before node deletion.</td>
|
|
270
|
+
<td><code>true</code></td>
|
|
271
|
+
</tr>
|
|
272
|
+
<tr>
|
|
273
|
+
<td>object_layout</td>
|
|
274
|
+
<td>The default value of `format` for objects. If set to <code>table</code> for example, objects will use table layout if `format` is not specified.</td>
|
|
275
|
+
<td><code>normal</code></td>
|
|
276
|
+
</tr>
|
|
277
|
+
<tr>
|
|
278
|
+
<td>enum_source_value_auto_select</td>
|
|
279
|
+
<td>Preserve value at Move Up or Down.(No value is selected automatically upon deletion.)</td>
|
|
280
|
+
<td><code>true</code></td>
|
|
281
|
+
</tr>
|
|
282
|
+
<tr>
|
|
283
|
+
<td>max_depth</td>
|
|
284
|
+
<td>Max depth of the nested properties to be rendered of provided json schema. The missing of this option could cause "maximum call stack size exceeded" in case of object properties with circular references. <code>0</code> value means "render all".</td>
|
|
285
|
+
<td><code>0</code></td>
|
|
286
|
+
</tr>
|
|
287
|
+
<tr>
|
|
288
|
+
<td>use_default_values</td>
|
|
289
|
+
<td>If true default values based on the "type" of the property will be used</td>
|
|
290
|
+
<td><code>true</code></td>
|
|
291
|
+
</tr>
|
|
292
|
+
<tr>
|
|
293
|
+
<td>urn_resolver</td>
|
|
294
|
+
<td>A callback function to resolve an undefined Uniform Resource Name (URN) for <code>$ref</code>. The function receives a URN and callback to pass back a serialized JSON response. The function should return a boolean (true if the URN can be resolved; false otherwise).</td>
|
|
295
|
+
<td><code>false</code></td>
|
|
296
|
+
</tr>
|
|
297
|
+
</tbody>
|
|
298
|
+
</table>
|
|
299
|
+
|
|
300
|
+
__*Note__ If the `ajax` property is `true` and JSON Editor needs to fetch an external url, the api methods won't be available immediately.
|
|
301
|
+
Listen for the `ready` event before calling them.
|
|
302
|
+
|
|
303
|
+
```js
|
|
304
|
+
editor.on('ready',() => {
|
|
305
|
+
// Now the api methods will be available
|
|
306
|
+
editor.validate();
|
|
307
|
+
});
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### Get/Set Value
|
|
311
|
+
|
|
312
|
+
```js
|
|
313
|
+
editor.setValue({name: "John Smith"});
|
|
314
|
+
|
|
315
|
+
const value = editor.getValue();
|
|
316
|
+
console.log(value.name) // Will log "John Smith"
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Instead of getting/setting the value of the entire editor, you can also work on individual parts of the schema:
|
|
320
|
+
|
|
321
|
+
```js
|
|
322
|
+
// Get a reference to a node within the editor
|
|
323
|
+
const name = editor.getEditor('root.name');
|
|
324
|
+
|
|
325
|
+
// `getEditor` will return null if the path is invalid
|
|
326
|
+
if (name) {
|
|
327
|
+
name.setValue("John Smith");
|
|
328
|
+
|
|
329
|
+
console.log(name.getValue());
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Validate
|
|
334
|
+
|
|
335
|
+
When feasible, JSON Editor won't let users enter invalid data. This is done by
|
|
336
|
+
using input masks and intelligently enabling/disabling controls.
|
|
337
|
+
|
|
338
|
+
However, in some cases it is still possible to enter data that doesn't validate against the schema.
|
|
339
|
+
|
|
340
|
+
You can use the `validate` method to check if the data is valid or not.
|
|
341
|
+
|
|
342
|
+
```javascript
|
|
343
|
+
// Validate the editor's current value against the schema
|
|
344
|
+
const errors = editor.validate();
|
|
345
|
+
|
|
346
|
+
if (errors.length) {
|
|
347
|
+
// errors is an array of objects, each with a `path`, `property`, and `message` parameter
|
|
348
|
+
// `property` is the schema keyword that triggered the validation error (e.g. "minLength")
|
|
349
|
+
// `path` is a dot separated path into the JSON object (e.g. "root.path.to.field")
|
|
350
|
+
console.log(errors);
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
// It's valid!
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
By default, this will do the validation with the editor's current value.
|
|
358
|
+
If you want to use a different value, you can pass it in as a parameter.
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
```javascript
|
|
362
|
+
// Validate an arbitrary value against the editor's schema
|
|
363
|
+
const errors = editor.validate({
|
|
364
|
+
value: {
|
|
365
|
+
to: "test"
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### Listen for Changes
|
|
371
|
+
|
|
372
|
+
The `change` event is fired whenever the editor's value changes.
|
|
373
|
+
|
|
374
|
+
```javascript
|
|
375
|
+
editor.on('change',() => {
|
|
376
|
+
// Do something
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
editor.off('change',function_reference);
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
You can also watch a specific field for changes:
|
|
383
|
+
|
|
384
|
+
```javascript
|
|
385
|
+
editor.watch('path.to.field',() => {
|
|
386
|
+
// Do something
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
editor.unwatch('path.to.field',function_reference);
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
Or watch all fields (Similar to the "onchange" event, but tracks the field changed)
|
|
393
|
+
|
|
394
|
+
```javascript
|
|
395
|
+
const watcherCallback = function (path) {
|
|
396
|
+
console.log(`field with path: [${path}] changed to [${JSON.stringify(this.getEditor(path).getValue())}]`);
|
|
397
|
+
// Do something
|
|
398
|
+
}
|
|
399
|
+
for (let key in editor.editors) {
|
|
400
|
+
if (editor.editors.hasOwnProperty(key) && key !== 'root') {
|
|
401
|
+
editor.watch(key, watcherCallback.bind(editor, key));
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
### Enable and Disable the Editor
|
|
407
|
+
|
|
408
|
+
This lets you disable editing for the entire form or part of the form.
|
|
409
|
+
|
|
410
|
+
```js
|
|
411
|
+
// Disable entire form
|
|
412
|
+
editor.disable();
|
|
413
|
+
|
|
414
|
+
// Disable part of the form
|
|
415
|
+
editor.getEditor('root.location').disable();
|
|
416
|
+
|
|
417
|
+
// Enable entire form
|
|
418
|
+
editor.enable();
|
|
419
|
+
|
|
420
|
+
// Enable part of the form
|
|
421
|
+
editor.getEditor('root.location').enable();
|
|
422
|
+
|
|
423
|
+
// Check if form is currently enabled
|
|
424
|
+
if(editor.isEnabled()) alert("It's editable!");
|
|
425
|
+
|
|
426
|
+
// Activate part of the form
|
|
427
|
+
editor.activate();
|
|
428
|
+
|
|
429
|
+
// Deactivate part of the form
|
|
430
|
+
editor.deactivate();
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
### Destroy
|
|
434
|
+
|
|
435
|
+
This removes the editor HTML from the DOM and frees up resources.
|
|
436
|
+
|
|
437
|
+
```javascript
|
|
438
|
+
editor.destroy();
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
CSS Integration
|
|
442
|
+
----------------
|
|
443
|
+
JSON Editor can integrate with several popular CSS frameworks out of the box.
|
|
444
|
+
|
|
445
|
+
The currently supported themes are:
|
|
446
|
+
|
|
447
|
+
* barebones
|
|
448
|
+
* html (the default)
|
|
449
|
+
* bootstrap4
|
|
450
|
+
* spectre
|
|
451
|
+
* tailwind
|
|
452
|
+
|
|
453
|
+
Note: The following themes have NOT been updated to 2.x format and will be removed in final version unless there's someone willing to update those.
|
|
454
|
+
Old 1.x themes displays the message **"This is an old JSON-Editor 1.x Theme and might not display elements correctly when used with the 2.x version"** at the bottom of the form output.
|
|
455
|
+
|
|
456
|
+
* bootstrap2
|
|
457
|
+
* bootstrap3
|
|
458
|
+
* foundation3
|
|
459
|
+
* foundation4
|
|
460
|
+
* foundation5
|
|
461
|
+
* foundation6
|
|
462
|
+
* jqueryui
|
|
463
|
+
* materialize
|
|
464
|
+
|
|
465
|
+
The default theme is `html`, which does not rely on an external framework.
|
|
466
|
+
This default can be changed by setting the `JSONEditor.defaults.options.theme` variable.
|
|
467
|
+
|
|
468
|
+
If you want to specify your own styles with CSS, you can use `barebones`, which includes almost no classes or inline styles.
|
|
469
|
+
|
|
470
|
+
```javascript
|
|
471
|
+
JSONEditor.defaults.options.theme = 'spectre';
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
You can override this default on a per-instance basis by passing a `theme` parameter in when initializing:
|
|
475
|
+
|
|
476
|
+
```js
|
|
477
|
+
const editor = new JSONEditor(element,{
|
|
478
|
+
schema: schema,
|
|
479
|
+
theme: 'tailwind'
|
|
480
|
+
});
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
### Icon Libraries
|
|
484
|
+
|
|
485
|
+
JSON Editor also supports several popular icon libraries. The icon library must be set independently of the theme, even though there is some overlap.
|
|
486
|
+
|
|
487
|
+
The supported icon libs are:
|
|
488
|
+
|
|
489
|
+
* jqueryui
|
|
490
|
+
* fontawesome3
|
|
491
|
+
* fontawesome4
|
|
492
|
+
* fontawesome5
|
|
493
|
+
* openiconic
|
|
494
|
+
* spectre
|
|
495
|
+
|
|
496
|
+
By default, no icons are used. Just like the CSS theme, you can set the icon lib globally or when initializing:
|
|
497
|
+
|
|
498
|
+
```js
|
|
499
|
+
// Set the global default
|
|
500
|
+
JSONEditor.defaults.options.iconlib = "spectre";
|
|
501
|
+
|
|
502
|
+
// Set the icon lib during initialization
|
|
503
|
+
const editor = new JSONEditor(element,{
|
|
504
|
+
schema: schema,
|
|
505
|
+
iconlib: "fontawesome4"
|
|
506
|
+
});
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
It's possible to create your own custom themes and/or icon libs as well. Look at any of the existing classes for examples.
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
JSON Schema Support
|
|
513
|
+
-----------------
|
|
514
|
+
|
|
515
|
+
JSON Editor fully supports version 3 and 4 of the JSON Schema [core][core] and [validation][validation] specifications.
|
|
516
|
+
Some of The [hyper-schema][hyper] specification is supported as well.
|
|
517
|
+
|
|
518
|
+
[core]: http://json-schema.org/latest/json-schema-core.html
|
|
519
|
+
[validation]: http://json-schema.org/latest/json-schema-validation.html
|
|
520
|
+
[hyper]: http://json-schema.org/latest/json-schema-hypermedia.html
|
|
521
|
+
|
|
522
|
+
### $ref and definitions
|
|
523
|
+
|
|
524
|
+
JSON Editor supports schema references to external URLs and local definitions. Here's an example showing both:
|
|
525
|
+
|
|
526
|
+
```json
|
|
527
|
+
{
|
|
528
|
+
"type": "object",
|
|
529
|
+
"properties": {
|
|
530
|
+
"name": {
|
|
531
|
+
"title": "Full Name",
|
|
532
|
+
"$ref": "#/definitions/name"
|
|
533
|
+
},
|
|
534
|
+
"location": {
|
|
535
|
+
"$ref": "http://mydomain.com/geo.json"
|
|
536
|
+
}
|
|
537
|
+
},
|
|
538
|
+
"definitions": {
|
|
539
|
+
"name": {
|
|
540
|
+
"type": "string",
|
|
541
|
+
"minLength": 5
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
Local references must point to the `definitions` object of the root node of the schema.
|
|
548
|
+
So, `#/customkey/name` will throw an exception.
|
|
549
|
+
|
|
550
|
+
If loading an external url via Ajax, the url must either be on the same domain or return the correct HTTP cross domain headers.
|
|
551
|
+
If your URLs don't meet this requirement, you can pass in the references to JSON Editor during initialization (see Usage section above).
|
|
552
|
+
|
|
553
|
+
Self-referential $refs are supported. Check out `examples/recursive.html` for usage examples.
|
|
554
|
+
|
|
555
|
+
### hyper-schema links
|
|
556
|
+
|
|
557
|
+
The `links` keyword from the hyper-schema specification can be used to add links to related documents.
|
|
558
|
+
|
|
559
|
+
JSON Editor will use the `mediaType` property of the links to determine how best to display them.
|
|
560
|
+
Image, audio, and video links will display the media inline as well as providing a text link.
|
|
561
|
+
|
|
562
|
+
Here are a couple examples:
|
|
563
|
+
|
|
564
|
+
Simple text link
|
|
565
|
+
```js+jinja
|
|
566
|
+
{
|
|
567
|
+
"title": "Blog Post Id",
|
|
568
|
+
"type": "integer",
|
|
569
|
+
"links": [
|
|
570
|
+
{
|
|
571
|
+
"rel": "comments",
|
|
572
|
+
"href": "/posts/{{self}}/comments/",
|
|
573
|
+
// Optional - set CSS classes for the link
|
|
574
|
+
"class": "comment-link open-in-modal primary-text"
|
|
575
|
+
}
|
|
576
|
+
]
|
|
577
|
+
}
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
Make link download when clicked
|
|
581
|
+
```js+jinja
|
|
582
|
+
{
|
|
583
|
+
"title": "Document filename",
|
|
584
|
+
"type": "string",
|
|
585
|
+
"links": [
|
|
586
|
+
{
|
|
587
|
+
"rel": "Download File",
|
|
588
|
+
"href": "/documents/{{self}}",
|
|
589
|
+
// Can also set `download` to a string as per the HTML5 spec
|
|
590
|
+
"download": true
|
|
591
|
+
}
|
|
592
|
+
]
|
|
593
|
+
}
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
Show a video preview (using HTML5 video)
|
|
597
|
+
```js+jinja
|
|
598
|
+
{
|
|
599
|
+
"title": "Video filename",
|
|
600
|
+
"type": "string",
|
|
601
|
+
"links": [
|
|
602
|
+
{
|
|
603
|
+
"href": "/videos/{{self}}.mp4",
|
|
604
|
+
"mediaType": "video/mp4"
|
|
605
|
+
}
|
|
606
|
+
]
|
|
607
|
+
}
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
The `href` property is a template that gets re-evaluated every time the value changes.
|
|
611
|
+
The variable `self` is always available. Look at the __Dependencies__ section below for how to include other fields or use a custom template engine.
|
|
612
|
+
|
|
613
|
+
### Property Ordering
|
|
614
|
+
|
|
615
|
+
There is no way to specify property ordering in JSON Schema (although this may change in v5 of the spec).
|
|
616
|
+
|
|
617
|
+
JSON Editor introduces a new keyword `propertyOrder` for this purpose. The default property order if unspecified is 1000. Properties with the same order will use normal JSON key ordering.
|
|
618
|
+
|
|
619
|
+
```json
|
|
620
|
+
{
|
|
621
|
+
"type": "object",
|
|
622
|
+
"properties": {
|
|
623
|
+
"prop1": {
|
|
624
|
+
"type": "string"
|
|
625
|
+
},
|
|
626
|
+
"prop2": {
|
|
627
|
+
"type": "string",
|
|
628
|
+
"propertyOrder": 10
|
|
629
|
+
},
|
|
630
|
+
"prop3": {
|
|
631
|
+
"type": "string",
|
|
632
|
+
"propertyOrder": 1001
|
|
633
|
+
},
|
|
634
|
+
"prop4": {
|
|
635
|
+
"type": "string",
|
|
636
|
+
"propertyOrder": 1
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
In the above example schema, `prop1` does not have an order specified, so it will default to 1000.
|
|
643
|
+
So, the final order of properties in the form (and in returned JSON data) will be:
|
|
644
|
+
|
|
645
|
+
1. prop4 (order 1)
|
|
646
|
+
2. prop2 (order 10)
|
|
647
|
+
3. prop1 (order 1000)
|
|
648
|
+
4. prop3 (order 1001)
|
|
649
|
+
|
|
650
|
+
### Default Properties
|
|
651
|
+
|
|
652
|
+
The default behavior of JSON Editor is to include all object properties defined with the `properties` keyword.
|
|
653
|
+
|
|
654
|
+
To override this behaviour, you can use the keyword `defaultProperties` to set which ones are included:
|
|
655
|
+
|
|
656
|
+
```json
|
|
657
|
+
{
|
|
658
|
+
"type": "object",
|
|
659
|
+
"properties": {
|
|
660
|
+
"name": {"type": "string"},
|
|
661
|
+
"age": {"type": "integer"}
|
|
662
|
+
},
|
|
663
|
+
"defaultProperties": ["name"]
|
|
664
|
+
}
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
Now, only the `name` property above will be included by default. You can use the "Object Properties" button
|
|
668
|
+
to add the "age" property back in.
|
|
669
|
+
|
|
670
|
+
### format
|
|
671
|
+
|
|
672
|
+
JSON Editor supports many different formats for schemas of type `string`. They will work with schemas of type `integer` and `number` as well, but some formats may produce weird results.
|
|
673
|
+
If the `enum` property is specified, `format` will be ignored.
|
|
674
|
+
|
|
675
|
+
JSON Editor uses HTML5 input types, so some of these may render as basic text input in older browsers:
|
|
676
|
+
|
|
677
|
+
* color
|
|
678
|
+
* date
|
|
679
|
+
* datetime
|
|
680
|
+
* datetime-local
|
|
681
|
+
* email
|
|
682
|
+
* month
|
|
683
|
+
* password
|
|
684
|
+
* number
|
|
685
|
+
* range
|
|
686
|
+
* tel
|
|
687
|
+
* text
|
|
688
|
+
* textarea
|
|
689
|
+
* time
|
|
690
|
+
* url
|
|
691
|
+
* week
|
|
692
|
+
|
|
693
|
+
Here is an example that will show a color picker in browsers that support it:
|
|
694
|
+
|
|
695
|
+
```json
|
|
696
|
+
{
|
|
697
|
+
"type": "object",
|
|
698
|
+
"properties": {
|
|
699
|
+
"color": {
|
|
700
|
+
"type": "string",
|
|
701
|
+
"format": "color"
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
```
|
|
706
|
+
|
|
707
|
+
#### String Editors Input Attributes
|
|
708
|
+
|
|
709
|
+
You can set custom attributes such as **placeholder**, **class** and **data-** on the input field using the special options keyword `inputAttributes`.
|
|
710
|
+
|
|
711
|
+
Like this:
|
|
712
|
+
|
|
713
|
+
```json
|
|
714
|
+
{
|
|
715
|
+
"type": "object",
|
|
716
|
+
"properties": {
|
|
717
|
+
"name": {
|
|
718
|
+
"title": "Full Name",
|
|
719
|
+
"options": {
|
|
720
|
+
"inputAttributes": {
|
|
721
|
+
"placeholder": "your name here...",
|
|
722
|
+
"class": "myclass"
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
```
|
|
729
|
+
|
|
730
|
+
#### Specialized String Editors
|
|
731
|
+
|
|
732
|
+
In addition to the standard HTML input formats, JSON Editor can also integrate with several 3rd party specialized editors. These libraries are not included in JSON Editor and you must load them on the page yourself.
|
|
733
|
+
|
|
734
|
+
__SCEditor__ provides WYSIWYG editing of HTML and BBCode. To use it, set the format to `html` or `bbcode` and set the `wysiwyg` option to `true`:
|
|
735
|
+
|
|
736
|
+
```json
|
|
737
|
+
{
|
|
738
|
+
"type": "string",
|
|
739
|
+
"format": "html",
|
|
740
|
+
"options": {
|
|
741
|
+
"wysiwyg": true
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
__SimpleMDE__ is a simple Markdown editor with live preview. To use it, set the format to `markdown`:
|
|
748
|
+
|
|
749
|
+
```json
|
|
750
|
+
{
|
|
751
|
+
"type": "string",
|
|
752
|
+
"format": "markdown"
|
|
753
|
+
}
|
|
754
|
+
```
|
|
755
|
+
|
|
756
|
+
__Ace Editor__ is a syntax highlighting source code editor. You can use it by setting the format to any of the following:
|
|
757
|
+
|
|
758
|
+
* actionscript
|
|
759
|
+
* batchfile
|
|
760
|
+
* c
|
|
761
|
+
* c++
|
|
762
|
+
* cpp (alias for c++)
|
|
763
|
+
* coffee
|
|
764
|
+
* csharp
|
|
765
|
+
* css
|
|
766
|
+
* dart
|
|
767
|
+
* django
|
|
768
|
+
* ejs
|
|
769
|
+
* erlang
|
|
770
|
+
* golang
|
|
771
|
+
* groovy
|
|
772
|
+
* handlebars
|
|
773
|
+
* haskell
|
|
774
|
+
* haxe
|
|
775
|
+
* html
|
|
776
|
+
* ini
|
|
777
|
+
* jade
|
|
778
|
+
* java
|
|
779
|
+
* javascript
|
|
780
|
+
* json
|
|
781
|
+
* less
|
|
782
|
+
* lisp
|
|
783
|
+
* lua
|
|
784
|
+
* makefile
|
|
785
|
+
* markdown
|
|
786
|
+
* matlab
|
|
787
|
+
* mysql
|
|
788
|
+
* objectivec
|
|
789
|
+
* pascal
|
|
790
|
+
* perl
|
|
791
|
+
* pgsql
|
|
792
|
+
* php
|
|
793
|
+
* python
|
|
794
|
+
* r
|
|
795
|
+
* ruby
|
|
796
|
+
* sass
|
|
797
|
+
* scala
|
|
798
|
+
* scss
|
|
799
|
+
* smarty
|
|
800
|
+
* sql
|
|
801
|
+
* stylus
|
|
802
|
+
* svg
|
|
803
|
+
* twig
|
|
804
|
+
* vbscript
|
|
805
|
+
* xml
|
|
806
|
+
* yaml
|
|
807
|
+
|
|
808
|
+
```json
|
|
809
|
+
{
|
|
810
|
+
"type": "string",
|
|
811
|
+
"format": "yaml"
|
|
812
|
+
}
|
|
813
|
+
```
|
|
814
|
+
|
|
815
|
+
You can use the hyper-schema keyword `media` instead of `format` too if you prefer for formats with a mime type:
|
|
816
|
+
|
|
817
|
+
```json
|
|
818
|
+
{
|
|
819
|
+
"type": "string",
|
|
820
|
+
"media": {
|
|
821
|
+
"type": "text/html"
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
```
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
You can enable [Ace editor options](https://github.com/ajaxorg/ace/wiki/Configuring-Ace) individually by setting the `options.ace` in schema.
|
|
828
|
+
|
|
829
|
+
```json
|
|
830
|
+
{
|
|
831
|
+
"type": "string",
|
|
832
|
+
"format": "sql",
|
|
833
|
+
"options": {
|
|
834
|
+
"ace": {
|
|
835
|
+
"theme": "ace/theme/vibrant_ink",
|
|
836
|
+
"tabSize": 2,
|
|
837
|
+
"useSoftTabs": true,
|
|
838
|
+
"wrap": true
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
```
|
|
843
|
+
|
|
844
|
+
#### Booleans
|
|
845
|
+
|
|
846
|
+
The default boolean editor is a select box with options "true" and "false". To use a checkbox instead, set the format to `checkbox`.
|
|
847
|
+
|
|
848
|
+
```json
|
|
849
|
+
{
|
|
850
|
+
"type": "boolean",
|
|
851
|
+
"format": "checkbox"
|
|
852
|
+
}
|
|
853
|
+
```
|
|
854
|
+
|
|
855
|
+
#### Arrays
|
|
856
|
+
|
|
857
|
+
The default array editor takes up a lot of screen real estate. The `table` and `tabs` formats provide more compact UIs for editing arrays.
|
|
858
|
+
|
|
859
|
+
The `table` format works great when every array element has the same schema and is not too complex.
|
|
860
|
+
|
|
861
|
+
The `tabs` format can handle any array, but only shows one array element at a time. It has tabs on the left for switching between items.
|
|
862
|
+
|
|
863
|
+
The `tabs-top` format place tabs on the top.
|
|
864
|
+
|
|
865
|
+
Here's an example of the `table` format:
|
|
866
|
+
|
|
867
|
+
```json
|
|
868
|
+
{
|
|
869
|
+
"type": "array",
|
|
870
|
+
"format": "table",
|
|
871
|
+
"items": {
|
|
872
|
+
"type": "object",
|
|
873
|
+
"properties": {
|
|
874
|
+
"name": {
|
|
875
|
+
"type": "string"
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
```
|
|
881
|
+
|
|
882
|
+
For arrays of enumerated strings, you can also use the `select` or `checkbox` format. These formats require a very specific schema to work:
|
|
883
|
+
|
|
884
|
+
```json
|
|
885
|
+
{
|
|
886
|
+
"type": "array",
|
|
887
|
+
"uniqueItems": true,
|
|
888
|
+
"items": {
|
|
889
|
+
"type": "string",
|
|
890
|
+
"enum": ["value1","value2"]
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
```
|
|
894
|
+
|
|
895
|
+
By default, the `checkbox` editor (multiple checkboxes) will be used if there are fewer than 8 enum options. Otherwise, the `select` editor (a multiselect box) will be used.
|
|
896
|
+
|
|
897
|
+
You can override this default by passing in a format:
|
|
898
|
+
|
|
899
|
+
```json
|
|
900
|
+
{
|
|
901
|
+
"type": "array",
|
|
902
|
+
"format": "select",
|
|
903
|
+
"uniqueItems": true,
|
|
904
|
+
"items": {
|
|
905
|
+
"type": "string",
|
|
906
|
+
"enum": ["value1","value2"]
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
```
|
|
910
|
+
|
|
911
|
+
#### Array events
|
|
912
|
+
|
|
913
|
+
When an array item is added, removed, moved up, moved or removed the json editor will trigger a relative event.
|
|
914
|
+
|
|
915
|
+
```javascript
|
|
916
|
+
editor.on('moveRow', editor => {
|
|
917
|
+
console.log('moveRow', editor)
|
|
918
|
+
});
|
|
919
|
+
editor.on('addRow', editor => {
|
|
920
|
+
console.log('addRow', editor)
|
|
921
|
+
});
|
|
922
|
+
editor.on('deleteRow', editor => {
|
|
923
|
+
console.log('deleteRow', editor)
|
|
924
|
+
});
|
|
925
|
+
editor.on('deleteAllRows', editor => {
|
|
926
|
+
console.log('deleteAllRows', editor)
|
|
927
|
+
});
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
#### Objects
|
|
932
|
+
|
|
933
|
+
The default object layout is one child editor per row. The `grid` format will instead put multiple child editors per row.
|
|
934
|
+
This can make the editor much more compact, but at a cost of not guaranteeing child editor order. This format will stretch
|
|
935
|
+
columns to fill gaps untill all the 12 columns are filled.
|
|
936
|
+
|
|
937
|
+
```json
|
|
938
|
+
{
|
|
939
|
+
"type": "object",
|
|
940
|
+
"properties": {
|
|
941
|
+
"name": { "type": "string" }
|
|
942
|
+
},
|
|
943
|
+
"format": "grid"
|
|
944
|
+
}
|
|
945
|
+
```
|
|
946
|
+
|
|
947
|
+
The `grid-strict` format instead will respect columns sizes (no stretching) and properties order.
|
|
948
|
+
It introduces the new `grid-break` property to breaks the current row leaving a 4 colums gap.
|
|
949
|
+
|
|
950
|
+
```json
|
|
951
|
+
{
|
|
952
|
+
"type": "object",
|
|
953
|
+
"format": "grid-strict",
|
|
954
|
+
"properties": {
|
|
955
|
+
"a": {
|
|
956
|
+
"title": "a",
|
|
957
|
+
"type": "string",
|
|
958
|
+
"options": {
|
|
959
|
+
"grid_columns": 4
|
|
960
|
+
}
|
|
961
|
+
},
|
|
962
|
+
"b": {
|
|
963
|
+
"title": "b",
|
|
964
|
+
"type": "string",
|
|
965
|
+
"options": {
|
|
966
|
+
"grid_columns": 4,
|
|
967
|
+
"grid_break": true
|
|
968
|
+
}
|
|
969
|
+
},
|
|
970
|
+
"c": {
|
|
971
|
+
"title": "c",
|
|
972
|
+
"type": "string",
|
|
973
|
+
"options": {
|
|
974
|
+
"grid_columns": 6
|
|
975
|
+
}
|
|
976
|
+
},
|
|
977
|
+
"d": {
|
|
978
|
+
"title": "d",
|
|
979
|
+
"type": "string",
|
|
980
|
+
"options": {
|
|
981
|
+
"grid_columns": 6
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
```
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
The `categories` format groups properties in top-tabbed panels, one for each object or array property plus one that groups all added or other types of properties.
|
|
990
|
+
Panel tabs titles came from object or array titles and for the grouping panel it defaults to "Basic", unless `basicCategoryTitle` is defined.
|
|
991
|
+
|
|
992
|
+
```json
|
|
993
|
+
{
|
|
994
|
+
"type": "object",
|
|
995
|
+
"properties": {
|
|
996
|
+
"name": { "type": "string" }
|
|
997
|
+
},
|
|
998
|
+
"format": "categories",
|
|
999
|
+
"basicCategoryTitle": "Main"
|
|
1000
|
+
}
|
|
1001
|
+
```
|
|
1002
|
+
|
|
1003
|
+
Demo page will look like this:
|
|
1004
|
+
|
|
1005
|
+

|
|
1006
|
+
|
|
1007
|
+
Editor Options
|
|
1008
|
+
----------------
|
|
1009
|
+
|
|
1010
|
+
Editors can accept options which alter the behavior in some way.
|
|
1011
|
+
|
|
1012
|
+
* `collapsed` - If set to true, the editor will start collapsed (works for objects and arrays)
|
|
1013
|
+
* `disable_array_add` - If set to true, the "add row" button will be hidden (works for arrays)
|
|
1014
|
+
* `disable_array_delete` - If set to true, all of the "delete" buttons will be hidden (works for arrays)
|
|
1015
|
+
* `disable_array_delete_all_rows` - If set to true, just the "delete all rows" button will be hidden (works for arrays)
|
|
1016
|
+
* `disable_array_delete_last_row` - If set to true, just the "delete last row" buttons will be hidden (works for arrays)
|
|
1017
|
+
* `disable_array_reorder` - If set to true, the "move up/down" buttons will be hidden (works for arrays)
|
|
1018
|
+
* `disable_collapse` - If set to true, the collapse button will be hidden (works for objects and arrays)
|
|
1019
|
+
* `disable_edit_json` - If set to true, the Edit JSON button will be hidden (works for objects)
|
|
1020
|
+
* `disable_properties` - If set to true, the Edit Properties button will be hidden (works for objects)
|
|
1021
|
+
* `array_controls_top` - If set to true, array controls (add, delete etc) will be displayed at top of list (works for arrays)
|
|
1022
|
+
* `enum_titles` - An array of display values to use for select box options in the same order as defined with the `enum` keyword. Works with schema using enum values.
|
|
1023
|
+
* `expand_height` - If set to true, the input will auto expand/contract to fit the content. Works best with textareas.
|
|
1024
|
+
* `grid_columns` - Explicitly set the number of grid columns (1-12) for the editor if it's within an object using a grid layout.
|
|
1025
|
+
* `hidden` - If set to true, the editor will not appear in the UI (works for all types)
|
|
1026
|
+
* `input_height` - Explicitly set the height of the input element. Should be a valid CSS width string (e.g. "100px"). Works best with textareas.
|
|
1027
|
+
* `input_width` - Explicitly set the width of the input element. Should be a valid CSS width string (e.g. "100px"). Works for string, number, and integer data types.
|
|
1028
|
+
* `remove_empty_properties` - If set to true for an object, empty object properties (i.e. those with falsy values) will not be returned by getValue().
|
|
1029
|
+
|
|
1030
|
+
```json
|
|
1031
|
+
{
|
|
1032
|
+
"type": "object",
|
|
1033
|
+
"options": {
|
|
1034
|
+
"collapsed": true
|
|
1035
|
+
},
|
|
1036
|
+
"properties": {
|
|
1037
|
+
"name": {
|
|
1038
|
+
"type": "string"
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
```
|
|
1043
|
+
|
|
1044
|
+
You can globally set the default options too if you want:
|
|
1045
|
+
|
|
1046
|
+
```js
|
|
1047
|
+
JSONEditor.defaults.editors.object.options.collapsed = true;
|
|
1048
|
+
```
|
|
1049
|
+
InfoText
|
|
1050
|
+
------------------
|
|
1051
|
+
Using the option `infoText`, will create a info button, displaying the text you set, on hovering.
|
|
1052
|
+
|
|
1053
|
+
```json
|
|
1054
|
+
{
|
|
1055
|
+
"type": "string",
|
|
1056
|
+
"title": "Name",
|
|
1057
|
+
"options": {
|
|
1058
|
+
"infoText": "Your full name"
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
```
|
|
1062
|
+
|
|
1063
|
+
|
|
1064
|
+
Dependencies
|
|
1065
|
+
------------------
|
|
1066
|
+
Sometimes, it's necessary to have one field's value depend on another's.
|
|
1067
|
+
|
|
1068
|
+
The dependency information is fetched from the dependencies field in the options field of the control. The `dependencies` field should be a map where the keys are the names of the fields depended on and the value is the expected value. The value may be an array to indicate multiple value possibilities. This uses the internal field value watch system to notify fields of changes in their dependencies.
|
|
1069
|
+
|
|
1070
|
+
Here's an example schema:
|
|
1071
|
+
|
|
1072
|
+
```json
|
|
1073
|
+
{
|
|
1074
|
+
"title": "An object",
|
|
1075
|
+
"type": "object",
|
|
1076
|
+
"properties": {
|
|
1077
|
+
"fieldOne": {
|
|
1078
|
+
"title": "I should be changed to 'foo'",
|
|
1079
|
+
"type": "string",
|
|
1080
|
+
"enum": ["foo","bar"],
|
|
1081
|
+
"default": "bar"
|
|
1082
|
+
},
|
|
1083
|
+
"depender1": {
|
|
1084
|
+
"title": "I depend on fieldOne to be 'foo'",
|
|
1085
|
+
"type": "string",
|
|
1086
|
+
"enum": ["lorem","ipsum"],
|
|
1087
|
+
"options": {
|
|
1088
|
+
"dependencies": {
|
|
1089
|
+
"fieldOne": "foo"
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
},
|
|
1093
|
+
"depender2": {
|
|
1094
|
+
"title": "I depend on fieldOne to be 'bar'",
|
|
1095
|
+
"type": "string",
|
|
1096
|
+
"enum": ["dolor", "sit"],
|
|
1097
|
+
"options": {
|
|
1098
|
+
"dependencies": {
|
|
1099
|
+
"fieldOne": "bar"
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
```
|
|
1106
|
+
|
|
1107
|
+
The `dependencies` keyword from the JSON Schema specification is not nearly flexible enough to handle most use cases,
|
|
1108
|
+
so JSON Editor introduces a couple custom keywords that help in this regard.
|
|
1109
|
+
|
|
1110
|
+
The first step is to have a field "watch" other fields for changes.
|
|
1111
|
+
|
|
1112
|
+
```json
|
|
1113
|
+
{
|
|
1114
|
+
"type": "object",
|
|
1115
|
+
"properties": {
|
|
1116
|
+
"first_name": {
|
|
1117
|
+
"type": "string"
|
|
1118
|
+
},
|
|
1119
|
+
"last_name": {
|
|
1120
|
+
"type": "string"
|
|
1121
|
+
},
|
|
1122
|
+
"full_name": {
|
|
1123
|
+
"type": "string",
|
|
1124
|
+
"watch": {
|
|
1125
|
+
"fname": "first_name",
|
|
1126
|
+
"lname": "last_name"
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
```
|
|
1132
|
+
|
|
1133
|
+
The keyword `watch` tells JSON Editor which fields to watch for changes.
|
|
1134
|
+
|
|
1135
|
+
The keys (`fname` and `lname` in this example) are alphanumeric aliases for the fields.
|
|
1136
|
+
|
|
1137
|
+
The values (`first_name` and `last_name`) are paths to the fields. To access nested properties of objects, use a dot for separation (e.g. "path.to.field").
|
|
1138
|
+
|
|
1139
|
+
By default paths are from the root of the schema, but you can make the paths relative to any ancestor node with a schema `id` defined as well. This is especially useful within arrays. Here's an example:
|
|
1140
|
+
|
|
1141
|
+
```json
|
|
1142
|
+
{
|
|
1143
|
+
"type": "array",
|
|
1144
|
+
"items": {
|
|
1145
|
+
"type": "object",
|
|
1146
|
+
"id": "arr_item",
|
|
1147
|
+
"properties": {
|
|
1148
|
+
"first_name": {
|
|
1149
|
+
"type": "string"
|
|
1150
|
+
},
|
|
1151
|
+
"last_name": {
|
|
1152
|
+
"type": "string"
|
|
1153
|
+
},
|
|
1154
|
+
"full_name": {
|
|
1155
|
+
"type": "string",
|
|
1156
|
+
"watch": {
|
|
1157
|
+
"fname": "arr_item.first_name",
|
|
1158
|
+
"lname": "arr_item.last_name"
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
```
|
|
1165
|
+
|
|
1166
|
+
Now, the `full_name` field in each array element will watch the `first_name` and `last_name` fields within the same array element.
|
|
1167
|
+
|
|
1168
|
+
### Templates
|
|
1169
|
+
|
|
1170
|
+
Watching fields by itself doesn't do anything. For the example above, you need to tell JSON Editor that `full_name` should be `fname [space] lname`.
|
|
1171
|
+
JSON Editor uses a javascript template engine to accomplish this. A barebones template engine is included by default (simple `{{variable}}` replacement only), but many of the most popular template engines are also supported:
|
|
1172
|
+
|
|
1173
|
+
* ejs
|
|
1174
|
+
* handlebars
|
|
1175
|
+
* hogan
|
|
1176
|
+
* markup
|
|
1177
|
+
* mustache
|
|
1178
|
+
* swig
|
|
1179
|
+
* underscore >=1.7 (since 1.4.0, see also [#332](https://github.com/json-editor/json-editor/pull/332))
|
|
1180
|
+
|
|
1181
|
+
You can change the default by setting `JSONEditor.defaults.options.template` to one of the supported template engines:
|
|
1182
|
+
|
|
1183
|
+
```javascript
|
|
1184
|
+
JSONEditor.defaults.options.template = 'handlebars';
|
|
1185
|
+
```
|
|
1186
|
+
|
|
1187
|
+
You can set the template engine on a per-instance basis as well:
|
|
1188
|
+
|
|
1189
|
+
```js
|
|
1190
|
+
const editor = new JSONEditor(element,{
|
|
1191
|
+
schema: schema,
|
|
1192
|
+
template: 'hogan'
|
|
1193
|
+
});
|
|
1194
|
+
```
|
|
1195
|
+
|
|
1196
|
+
Here is the completed `full_name` example using the default barebones template engine:
|
|
1197
|
+
|
|
1198
|
+
```js+jinja
|
|
1199
|
+
{
|
|
1200
|
+
"type": "object",
|
|
1201
|
+
"properties": {
|
|
1202
|
+
"first_name": {
|
|
1203
|
+
"type": "string"
|
|
1204
|
+
},
|
|
1205
|
+
"last_name": {
|
|
1206
|
+
"type": "string"
|
|
1207
|
+
},
|
|
1208
|
+
"full_name": {
|
|
1209
|
+
"type": "string",
|
|
1210
|
+
"template": "{{fname}} {{lname}}",
|
|
1211
|
+
"watch": {
|
|
1212
|
+
"fname": "first_name",
|
|
1213
|
+
"lname": "last_name"
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
```
|
|
1219
|
+
|
|
1220
|
+
It is also possible to set the "template" property to a JavaScript callback function, defined under `window.JSONEditor.defaults.callbacks.template`. Inside the JavaScript callback, you have access to all the variables defined under the `watch` property + the current editor.
|
|
1221
|
+
|
|
1222
|
+
|
|
1223
|
+
Example Schema:
|
|
1224
|
+
```js+jinja
|
|
1225
|
+
{
|
|
1226
|
+
"type": "object",
|
|
1227
|
+
"properties": {
|
|
1228
|
+
"first_name": {
|
|
1229
|
+
"type": "string"
|
|
1230
|
+
},
|
|
1231
|
+
"last_name": {
|
|
1232
|
+
"type": "string"
|
|
1233
|
+
},
|
|
1234
|
+
"full_name": {
|
|
1235
|
+
"type": "string",
|
|
1236
|
+
"template": "callbackFunction",
|
|
1237
|
+
"watch": {
|
|
1238
|
+
"fname": "first_name",
|
|
1239
|
+
"lname": "last_name"
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
```
|
|
1245
|
+
Example Callback function:
|
|
1246
|
+
```js+jinja
|
|
1247
|
+
window.JSONEditor.defaults.callbacks.template = {
|
|
1248
|
+
"callbackFunction": (jseditor,e) => {
|
|
1249
|
+
return e.fname + " " + e.lname;
|
|
1250
|
+
}
|
|
1251
|
+
};
|
|
1252
|
+
```
|
|
1253
|
+
|
|
1254
|
+
### Enum Values
|
|
1255
|
+
|
|
1256
|
+
Another common dependency is a drop down menu whose possible values depend on other fields. Here's an example:
|
|
1257
|
+
|
|
1258
|
+
```json
|
|
1259
|
+
{
|
|
1260
|
+
"type": "object",
|
|
1261
|
+
"properties": {
|
|
1262
|
+
"possible_colors": {
|
|
1263
|
+
"type": "array",
|
|
1264
|
+
"items": {
|
|
1265
|
+
"type": "string"
|
|
1266
|
+
}
|
|
1267
|
+
},
|
|
1268
|
+
"primary_color": {
|
|
1269
|
+
"type": "string"
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
```
|
|
1274
|
+
|
|
1275
|
+
Let's say you want to force `primary_color` to be one of colors in the `possible_colors` array. First, we must tell the `primary_color` field to watch the `possible_colors` array.
|
|
1276
|
+
|
|
1277
|
+
```json
|
|
1278
|
+
{
|
|
1279
|
+
"primary_color": {
|
|
1280
|
+
"type": "string",
|
|
1281
|
+
"watch": {
|
|
1282
|
+
"colors": "possible_colors"
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
```
|
|
1287
|
+
|
|
1288
|
+
Then, we use the special keyword `enumSource` to tell JSON Editor that we want to use this field to populate a drop down.
|
|
1289
|
+
|
|
1290
|
+
```json
|
|
1291
|
+
{
|
|
1292
|
+
"primary_color": {
|
|
1293
|
+
"type": "string",
|
|
1294
|
+
"watch": {
|
|
1295
|
+
"colors": "possible_colors"
|
|
1296
|
+
},
|
|
1297
|
+
"enumSource": "colors"
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
```
|
|
1301
|
+
|
|
1302
|
+
Now, anytime the `possible_colors` array changes, the dropdown's values will be changed as well.
|
|
1303
|
+
|
|
1304
|
+
This is the most basic usage of `enumSource`. The more verbose form of this property supports
|
|
1305
|
+
filtering, pulling from multiple sources, constant values, etc..
|
|
1306
|
+
Here's a more complex example (this uses the Swig template engine syntax to show some advanced features)
|
|
1307
|
+
|
|
1308
|
+
```js+jinja
|
|
1309
|
+
{
|
|
1310
|
+
// An array of sources
|
|
1311
|
+
"enumSource": [
|
|
1312
|
+
// Constant values
|
|
1313
|
+
["none"],
|
|
1314
|
+
{
|
|
1315
|
+
// A watched field source
|
|
1316
|
+
"source": "colors",
|
|
1317
|
+
// Use a subset of the array
|
|
1318
|
+
"slice": [2,5],
|
|
1319
|
+
// Filter items with a template (if this renders to an empty string, it won't be included)
|
|
1320
|
+
"filter": "{% if item !== 'black' %}1{% endif %}",
|
|
1321
|
+
// Specify the display text for the enum option
|
|
1322
|
+
"title": "{{item|upper}}",
|
|
1323
|
+
// Specify the value property for the enum option
|
|
1324
|
+
"value": "{{item|trim}}"
|
|
1325
|
+
},
|
|
1326
|
+
// Another constant value at the end of the list
|
|
1327
|
+
["transparent"]
|
|
1328
|
+
]
|
|
1329
|
+
}
|
|
1330
|
+
```
|
|
1331
|
+
|
|
1332
|
+
You can also specify a list of static items with a slightly different syntax:
|
|
1333
|
+
|
|
1334
|
+
```js+jinja
|
|
1335
|
+
{
|
|
1336
|
+
"enumSource": [{
|
|
1337
|
+
// A watched field source
|
|
1338
|
+
"source": [
|
|
1339
|
+
{
|
|
1340
|
+
"value": 1,
|
|
1341
|
+
"title": "One"
|
|
1342
|
+
},
|
|
1343
|
+
{
|
|
1344
|
+
"value": 2,
|
|
1345
|
+
"title": "Two"
|
|
1346
|
+
}
|
|
1347
|
+
],
|
|
1348
|
+
"title": "{{item.title}}",
|
|
1349
|
+
"value": "{{item.value}}"
|
|
1350
|
+
}]
|
|
1351
|
+
]
|
|
1352
|
+
}
|
|
1353
|
+
```
|
|
1354
|
+
|
|
1355
|
+
The colors examples used an array of strings directly. Using the verbose form, you can
|
|
1356
|
+
also make it work with an array of objects. Here's an example:
|
|
1357
|
+
|
|
1358
|
+
```js+jinja
|
|
1359
|
+
{
|
|
1360
|
+
"type": "object",
|
|
1361
|
+
"properties": {
|
|
1362
|
+
"possible_colors": {
|
|
1363
|
+
"type": "array",
|
|
1364
|
+
"items": {
|
|
1365
|
+
"type": "object",
|
|
1366
|
+
"properties": {
|
|
1367
|
+
"text": {
|
|
1368
|
+
"type": "string"
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
},
|
|
1373
|
+
"primary_color": {
|
|
1374
|
+
"type": "string",
|
|
1375
|
+
"watch": {
|
|
1376
|
+
"colors": "possible_colors"
|
|
1377
|
+
},
|
|
1378
|
+
"enumSource": [{
|
|
1379
|
+
"source": "colors",
|
|
1380
|
+
"value": "{{item.text}}"
|
|
1381
|
+
}]
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
```
|
|
1386
|
+
|
|
1387
|
+
All of the optional templates in the verbose form have the properties `item` and `i` passed into them. `item` refers to the array element. `i` is the zero-based index.
|
|
1388
|
+
|
|
1389
|
+
#### JavaScript callbacks
|
|
1390
|
+
It is also possible to use JavaScript callback functions instead of templates for the enumSource properties properties: `value`, `title` and `filter`.
|
|
1391
|
+
|
|
1392
|
+
**Example Schema:**
|
|
1393
|
+
````json
|
|
1394
|
+
{
|
|
1395
|
+
"type": "object",
|
|
1396
|
+
"properties": {
|
|
1397
|
+
"possible_colors": {
|
|
1398
|
+
"type": "array",
|
|
1399
|
+
"format": "table",
|
|
1400
|
+
"items": {
|
|
1401
|
+
"type": "object",
|
|
1402
|
+
"properties": {
|
|
1403
|
+
"text": {
|
|
1404
|
+
"type": "string"
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
},
|
|
1409
|
+
"primary_color": {
|
|
1410
|
+
"type": "string",
|
|
1411
|
+
"watch": {
|
|
1412
|
+
"colors": "possible_colors"
|
|
1413
|
+
},
|
|
1414
|
+
"enumSource": [{
|
|
1415
|
+
"source": "colors",
|
|
1416
|
+
"filter": "enumFilterCB",
|
|
1417
|
+
"title": "enumTitleCB",
|
|
1418
|
+
"value": "enumValueCB"
|
|
1419
|
+
}]
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
````
|
|
1424
|
+
|
|
1425
|
+
**Example JavaScript callbacks:**
|
|
1426
|
+
````javascript
|
|
1427
|
+
window.JSONEditor.defaults.callbacks.template = {
|
|
1428
|
+
"enumFilterCB": (jseditor, e) => {
|
|
1429
|
+
if (e.item.text.toLowerCase() == 'red') return ""; // "red" is not allowed
|
|
1430
|
+
return e.item.text;
|
|
1431
|
+
},
|
|
1432
|
+
"enumTitleCB": (jseditor, e) => e.item.text.toUpperCase(),
|
|
1433
|
+
"enumValueCB": (jseditor, e) => e.item.text.toLowerCase()
|
|
1434
|
+
};
|
|
1435
|
+
````
|
|
1436
|
+
|
|
1437
|
+
#### Sorting
|
|
1438
|
+
|
|
1439
|
+
To sort the dynamic EnumSource, you can set the EnumSource property `sort` to either `asc` or `desc`.
|
|
1440
|
+
|
|
1441
|
+
|
|
1442
|
+
### Dynamic Headers
|
|
1443
|
+
|
|
1444
|
+
The `title` keyword of a schema is used to add user friendly headers to the editing UI. Sometimes though, dynamic headers, which change based on other fields, are helpful.
|
|
1445
|
+
|
|
1446
|
+
Consider the example of an array of children. Without dynamic headers, the UI for the array elements would show `Child 1`, `Child 2`, etc..
|
|
1447
|
+
It would be much nicer if the headers could be dynamic and incorporate information about the children, such as `1 - John (age 9)`, `2 - Sarah (age 11)`.
|
|
1448
|
+
|
|
1449
|
+
To accomplish this, use the `headerTemplate` property. All of the watched variables are passed into this template, along with the static title `title` (e.g. "Child"), the 0-based index `i0` (e.g. "0" and "1"), the 1-based index `i1`, and the field's value `self` (e.g. `{"name": "John", "age": 9}`).
|
|
1450
|
+
|
|
1451
|
+
```js+jinja
|
|
1452
|
+
{
|
|
1453
|
+
"type": "array",
|
|
1454
|
+
"title": "Children",
|
|
1455
|
+
"items": {
|
|
1456
|
+
"type": "object",
|
|
1457
|
+
"title": "Child",
|
|
1458
|
+
"headerTemplate": "{{ i1 }} - {{ self.name }} (age {{ self.age }})",
|
|
1459
|
+
"properties": {
|
|
1460
|
+
"name": { "type": "string" },
|
|
1461
|
+
"age": { "type": "integer" }
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
```
|
|
1466
|
+
|
|
1467
|
+
### Custom Template Engines
|
|
1468
|
+
|
|
1469
|
+
If one of the included template engines isn't sufficient,
|
|
1470
|
+
you can use any custom template engine with a `compile` method. For example:
|
|
1471
|
+
|
|
1472
|
+
```js
|
|
1473
|
+
const myengine = {
|
|
1474
|
+
compile: template =>
|
|
1475
|
+
// Compile should return a render function
|
|
1476
|
+
vars => {
|
|
1477
|
+
// A real template engine would render the template here
|
|
1478
|
+
const result = template;
|
|
1479
|
+
return result;
|
|
1480
|
+
}
|
|
1481
|
+
};
|
|
1482
|
+
|
|
1483
|
+
// Set globally
|
|
1484
|
+
JSONEditor.defaults.options.template = myengine;
|
|
1485
|
+
|
|
1486
|
+
// Set on a per-instance basis
|
|
1487
|
+
const editor = new JSONEditor(element,{
|
|
1488
|
+
schema: schema,
|
|
1489
|
+
template: myengine
|
|
1490
|
+
});
|
|
1491
|
+
```
|
|
1492
|
+
|
|
1493
|
+
Language and String Customization
|
|
1494
|
+
-----------------
|
|
1495
|
+
|
|
1496
|
+
JSON Editor uses a translate function to generate strings in the UI. A default `en` language mapping is provided.
|
|
1497
|
+
|
|
1498
|
+
You can easily override individual translations in the default language or create your own language mapping entirely.
|
|
1499
|
+
|
|
1500
|
+
```js+jinja
|
|
1501
|
+
// Override a specific translation
|
|
1502
|
+
JSONEditor.defaults.languages.en.error_minLength =
|
|
1503
|
+
"This better be at least {{0}} characters long or else!";
|
|
1504
|
+
|
|
1505
|
+
|
|
1506
|
+
// Create your own language mapping
|
|
1507
|
+
// Any keys not defined here will fall back to the "en" language
|
|
1508
|
+
JSONEditor.defaults.languages.es = {
|
|
1509
|
+
error_notset: "propiedad debe existir"
|
|
1510
|
+
};
|
|
1511
|
+
```
|
|
1512
|
+
|
|
1513
|
+
By default, all instances of JSON Editor will use the `en` language. To override this default, set the `JSONEditor.defaults.language` property.
|
|
1514
|
+
|
|
1515
|
+
```js
|
|
1516
|
+
JSONEditor.defaults.language = "es";
|
|
1517
|
+
```
|
|
1518
|
+
|
|
1519
|
+
Button Custimization
|
|
1520
|
+
-----------------
|
|
1521
|
+
|
|
1522
|
+
All buttons have classnames in the format `json-editor-btntype-*`. Using these classnames you can choose if the button should have icon or label hidden. The icon is wrapped in an `I` tag, the label is wrapped in a `SPAN` tag.
|
|
1523
|
+
|
|
1524
|
+
Examples:
|
|
1525
|
+
|
|
1526
|
+
Hide the icon on "Object Properties" button:
|
|
1527
|
+
```css
|
|
1528
|
+
.json-editor-btntype-properties i {
|
|
1529
|
+
display: none;
|
|
1530
|
+
}
|
|
1531
|
+
```
|
|
1532
|
+
|
|
1533
|
+
Hide the text on "Object Properties" button:
|
|
1534
|
+
```css
|
|
1535
|
+
.json-editor-btntype-properties span {
|
|
1536
|
+
display: none;
|
|
1537
|
+
}
|
|
1538
|
+
```
|
|
1539
|
+
|
|
1540
|
+
Custom Editor Interfaces
|
|
1541
|
+
-----------------
|
|
1542
|
+
|
|
1543
|
+
JSON Editor contains editor interfaces for each of the primitive JSON types as well as a few other specialized ones.
|
|
1544
|
+
|
|
1545
|
+
You can add custom editors interfaces fairly easily. Look at any of the existing ones for an example.
|
|
1546
|
+
|
|
1547
|
+
JSON Editor uses resolver functions to determine which editor interface to use for a particular schema or subschema.
|
|
1548
|
+
|
|
1549
|
+
Let's say you make a custom `location` editor for editing geo data. You can add a resolver function to use this custom editor when appropriate. For example:
|
|
1550
|
+
|
|
1551
|
+
```js
|
|
1552
|
+
// Add a resolver function to the beginning of the resolver list
|
|
1553
|
+
// This will make it run before any other ones
|
|
1554
|
+
JSONEditor.defaults.resolvers.unshift(schema => {
|
|
1555
|
+
if(schema.type === "object" && schema.format === "location") {
|
|
1556
|
+
return "location";
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
// If no valid editor is returned, the next resolver function will be used
|
|
1560
|
+
});
|
|
1561
|
+
```
|
|
1562
|
+
|
|
1563
|
+
The following schema will now use this custom editor for each of the array elements instead of the default `object` editor.
|
|
1564
|
+
|
|
1565
|
+
```json
|
|
1566
|
+
{
|
|
1567
|
+
"type": "array",
|
|
1568
|
+
"items": {
|
|
1569
|
+
"type": "object",
|
|
1570
|
+
"format": "location",
|
|
1571
|
+
"properties": {
|
|
1572
|
+
"longitude": {
|
|
1573
|
+
"type": "number"
|
|
1574
|
+
},
|
|
1575
|
+
"latitude": {
|
|
1576
|
+
"type": "number"
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
```
|
|
1582
|
+
|
|
1583
|
+
If you create a custom editor interface that you think could be helpful to others, submit a pull request!
|
|
1584
|
+
|
|
1585
|
+
The possibilities are endless. Some ideas:
|
|
1586
|
+
|
|
1587
|
+
* A compact way to edit objects
|
|
1588
|
+
* Radio button version of the `select` editor
|
|
1589
|
+
* Autosuggest for strings (like enum, but not restricted to those values)
|
|
1590
|
+
* Better editor for arrays of strings (tag editor)
|
|
1591
|
+
* Canvas based image editor that produces Base64 data URLs
|
|
1592
|
+
|
|
1593
|
+
Custom Validation
|
|
1594
|
+
----------------
|
|
1595
|
+
|
|
1596
|
+
JSON Editor provides a hook into the validation engine for adding your own custom validation.
|
|
1597
|
+
|
|
1598
|
+
Let's say you want to force all schemas with `format` set to `date` to match the pattern `YYYY-MM-DD`.
|
|
1599
|
+
|
|
1600
|
+
```js
|
|
1601
|
+
// Custom validators must return an array of errors or an empty array if valid
|
|
1602
|
+
JSONEditor.defaults.custom_validators.push((schema, value, path) => {
|
|
1603
|
+
const errors = [];
|
|
1604
|
+
if (schema.format==="date") {
|
|
1605
|
+
if (!/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test(value)) {
|
|
1606
|
+
// Errors must be an object with `path`, `property`, and `message`
|
|
1607
|
+
errors.push({
|
|
1608
|
+
path: path,
|
|
1609
|
+
property: 'format',
|
|
1610
|
+
message: 'Dates must be in the format "YYYY-MM-DD"'
|
|
1611
|
+
});
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
return errors;
|
|
1615
|
+
});
|
|
1616
|
+
```
|
|
1617
|
+
|
|
1618
|
+
Override Editors Methods
|
|
1619
|
+
----------------
|
|
1620
|
+
|
|
1621
|
+
```js
|
|
1622
|
+
// override class method
|
|
1623
|
+
JSONEditor.defaults.editors.integer.prototype.sanitize = function(value) {
|
|
1624
|
+
return value
|
|
1625
|
+
};
|
|
1626
|
+
```
|
|
1627
|
+
|
|
1628
|
+
or
|
|
1629
|
+
|
|
1630
|
+
```js
|
|
1631
|
+
// override object method
|
|
1632
|
+
var path ="root.integerfield";
|
|
1633
|
+
editor.getEditor(path).sanitize = function(value) {
|
|
1634
|
+
return value
|
|
1635
|
+
};
|
|
1636
|
+
```
|
|
1637
|
+
|
|
1638
|
+
Support Legacy Browser (not tested)
|
|
1639
|
+
----------------------
|
|
1640
|
+
|
|
1641
|
+
JSON Editor can be used with browsers that support ES5, but in order to use it with older browsers such as IE, it is necessary to use "core-js" as a polyfill.
|
|
1642
|
+
|
|
1643
|
+
```
|
|
1644
|
+
<script src="https://unpkg.com/core-js-bundle@latest/minified.js"></script>
|
|
1645
|
+
<script src="https://cdn.jsdelivr.net/npm/@json-editor/json-editor@latest/dist/jsoneditor.min.js"></script>
|
|
1646
|
+
```
|