@json-editor/json-editor 1.4.0-beta.0 → 1.17.0
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/.claude/settings.local.json +8 -0
- package/.env +2 -0
- package/.env-dist +2 -0
- package/.eslintrc +10 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +9 -0
- package/.github/workflows/build.yml +70 -0
- package/.travis.yml +62 -16
- package/CHANGELOG.md +483 -113
- package/CONTRIBUTING.md +43 -4
- package/Makefile +26 -0
- package/README.md +632 -121
- package/README_ADDON.md +577 -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 +146 -0
- package/config/helpers.js +10 -0
- package/config/karma.conf.js +89 -0
- package/config/readme.md +31 -0
- package/config/webpack.common.js +71 -0
- package/config/webpack.dev.js +15 -0
- package/config/webpack.nonmin.js +19 -0
- package/config/webpack.prod.js +24 -0
- package/dist/jsoneditor.js +2 -11550
- package/dist/jsoneditor.js.LICENSE.txt +15 -0
- package/dist/nonmin/jsoneditor.js +31392 -0
- package/dist/nonmin/jsoneditor.js.map +1 -0
- package/docs/basic.html +2 -2
- package/docs/basic_person.json +2 -1
- package/docs/choices.html +86 -0
- package/docs/cleave.html +11 -19
- package/docs/colorpicker.html +194 -0
- package/docs/css_integration.html +56 -54
- package/docs/custom-editor.html +92 -0
- package/docs/datetime.html +48 -21
- package/docs/describedby.html +42 -35
- package/docs/enumsource.html +67 -0
- package/docs/form-submission.html +162 -0
- package/docs/imask.html +192 -0
- package/docs/index.html +600 -582
- package/docs/materialize_css.html +1 -1
- package/docs/meta-schema.html +793 -0
- package/docs/meta_schema.json +446 -400
- package/docs/polyfills/assign.js +29 -0
- package/docs/radio.html +9 -17
- package/docs/recursive.html +15 -17
- package/docs/scripts/ajv-validator.js +8695 -0
- package/docs/select2.html +15 -9
- package/docs/selectize.html +11 -9
- package/docs/signature.html +12 -11
- package/docs/starrating.html +5 -17
- package/docs/upload.html +33 -23
- package/docs/uuid.html +70 -0
- package/docs/wysiwyg.html +14 -7
- package/jasmine.json +11 -0
- package/package.json +74 -25
- package/release-notes.md +90 -0
- package/src/core.js +411 -611
- package/src/defaults.js +381 -327
- package/src/editor.js +733 -544
- package/src/editors/ace.js +90 -0
- package/src/editors/array/choices.js +104 -0
- package/src/editors/array/select2.js +112 -0
- package/src/editors/array/selectize.js +107 -130
- package/src/editors/array.css +9 -0
- package/src/editors/array.css.js +3 -0
- package/src/editors/array.js +812 -695
- package/src/editors/autocomplete.js +59 -0
- package/src/editors/base64.js +148 -129
- package/src/editors/button.js +104 -0
- package/src/editors/checkbox.js +111 -76
- package/src/editors/choices.css +3 -0
- package/src/editors/choices.css.js +3 -0
- package/src/editors/choices.js +71 -0
- package/src/editors/colorpicker.js +105 -0
- package/src/editors/datetime.js +93 -79
- package/src/editors/describedby.js +141 -125
- package/src/editors/enum.js +131 -116
- package/src/editors/hidden.js +100 -86
- package/src/editors/index.js +81 -0
- package/src/editors/info.js +28 -0
- package/src/editors/integer.js +21 -8
- package/src/editors/ip.js +36 -0
- package/src/editors/jodit.js +66 -0
- package/src/editors/multiple.js +380 -241
- package/src/editors/multiselect.js +207 -207
- package/src/editors/null.js +15 -11
- package/src/editors/number.js +39 -30
- package/src/editors/object.css +41 -0
- package/src/editors/object.css.js +3 -0
- package/src/editors/object.js +1190 -1068
- package/src/editors/radio.js +117 -101
- package/src/editors/sceditor.js +74 -0
- package/src/editors/select.js +318 -342
- package/src/editors/select2.js +112 -0
- package/src/editors/selectize.js +89 -338
- package/src/editors/signature.js +100 -104
- package/src/editors/simplemde.js +103 -0
- package/src/{styles → editors}/starrating.css +11 -2
- package/src/editors/starrating.css.js +3 -0
- package/src/editors/starrating.js +126 -95
- package/src/editors/stepper.js +27 -0
- package/src/editors/string.js +352 -426
- package/src/editors/table.js +486 -410
- package/src/editors/upload.js +297 -131
- package/src/editors/uuid.js +49 -0
- package/src/iconlib.js +22 -27
- package/src/iconlibs/bootstrap.js +28 -0
- package/src/iconlibs/bootstrap2.js +28 -17
- package/src/iconlibs/bootstrap3.js +28 -17
- package/src/iconlibs/fontawesome3.js +28 -17
- package/src/iconlibs/fontawesome4.js +28 -18
- package/src/iconlibs/fontawesome5.js +28 -18
- package/src/iconlibs/foundation2.js +24 -17
- package/src/iconlibs/foundation3.js +28 -17
- package/src/iconlibs/index.js +27 -0
- package/src/iconlibs/jqueryui.js +28 -17
- package/src/iconlibs/materialicons.js +49 -44
- package/src/iconlibs/openiconic.js +28 -0
- package/src/iconlibs/spectre.js +28 -0
- package/src/resolvers.js +135 -0
- package/src/schemaloader.js +639 -0
- package/src/style.css +157 -0
- package/src/style.css.js +3 -0
- package/src/templates/default.js +46 -51
- package/src/templates/ejs.js +8 -10
- package/src/templates/handlebars.js +1 -3
- package/src/templates/hogan.js +7 -9
- package/src/templates/index.js +21 -0
- package/src/templates/lodash.js +6 -8
- package/src/templates/markup.js +6 -8
- package/src/templates/mustache.js +6 -8
- package/src/templates/swig.js +1 -3
- package/src/templates/underscore.js +6 -8
- package/src/theme.js +717 -433
- package/src/themes/barebones.css +35 -0
- package/src/themes/barebones.css.js +3 -0
- package/src/themes/barebones.js +31 -0
- package/src/themes/bootstrap2.js +302 -265
- package/src/themes/bootstrap3.css +53 -0
- package/src/themes/bootstrap3.css.js +3 -0
- package/src/themes/bootstrap3.js +355 -262
- package/src/themes/bootstrap4.css +89 -0
- package/src/themes/bootstrap4.css.js +3 -0
- package/src/themes/bootstrap4.js +743 -237
- package/src/themes/bootstrap5.css +97 -0
- package/src/themes/bootstrap5.css.js +3 -0
- package/src/themes/bootstrap5.js +687 -0
- package/src/themes/foundation.js +535 -472
- package/src/themes/html.css +60 -0
- package/src/themes/html.css.js +3 -0
- package/src/themes/html.js +69 -82
- package/src/themes/index.js +29 -0
- package/src/themes/jqueryui.js +181 -167
- package/src/themes/materialize.js +263 -292
- package/src/themes/spectre.css +208 -0
- package/src/themes/spectre.css.js +3 -0
- package/src/themes/spectre.js +443 -0
- package/src/themes/tailwind.css +303 -0
- package/src/themes/tailwind.css.js +3 -0
- package/src/themes/tailwind.js +469 -0
- package/src/utilities.js +127 -68
- package/src/validator.js +909 -565
- package/src/validators/ip-validator.js +51 -0
- package/tests/Dockerfile +3 -0
- package/tests/README.md +25 -5
- package/tests/codeceptjs/codecept.json +9 -2
- package/tests/codeceptjs/constrains/contains_test.js +37 -0
- package/tests/codeceptjs/constrains/dependentRequired_test.js +33 -0
- package/tests/codeceptjs/constrains/dependentSchemas_test.js +16 -0
- package/tests/codeceptjs/constrains/if-then-else_test.js +186 -0
- package/tests/codeceptjs/core_test.js +534 -63
- package/tests/codeceptjs/editors/advanced_test.js +12 -9
- package/tests/codeceptjs/editors/array_any_of_test.js +50 -0
- package/tests/codeceptjs/editors/array_test.js +923 -657
- package/tests/codeceptjs/editors/autocomplete_test.js +15 -0
- package/tests/codeceptjs/editors/button_test.js +50 -0
- package/tests/codeceptjs/editors/checkbox_test.js +21 -6
- package/tests/codeceptjs/editors/colorpicker_test.js +29 -0
- package/tests/codeceptjs/editors/datetime_test.js +33 -0
- package/tests/codeceptjs/editors/inheritance_test.js +10 -0
- package/tests/codeceptjs/editors/integer_test.js +82 -64
- package/tests/codeceptjs/editors/jodit_test.js +23 -0
- package/tests/codeceptjs/editors/multiple_test.js +27 -0
- package/tests/codeceptjs/editors/multiselect_test.js +6 -7
- package/tests/codeceptjs/editors/number_test.js +75 -60
- package/tests/codeceptjs/editors/object_test.js +322 -80
- 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/purify_test.js +26 -0
- package/tests/codeceptjs/editors/radio_test.js +9 -0
- package/tests/codeceptjs/editors/range_test.js +10 -0
- package/tests/codeceptjs/editors/rating_test.js +10 -10
- package/tests/codeceptjs/editors/select_test.js +47 -18
- package/tests/codeceptjs/editors/starrating_test.js +15 -0
- package/tests/codeceptjs/editors/stepper_test.js +37 -0
- package/tests/codeceptjs/editors/string_test.js +107 -91
- package/tests/codeceptjs/editors/table-confirm-delete_test.js +60 -54
- package/tests/codeceptjs/editors/tabs_test.js +15 -11
- package/tests/codeceptjs/editors/uuid_test.js +48 -0
- package/tests/codeceptjs/editors/validation_test.js +13 -9
- package/tests/codeceptjs/issues/issue-gh-1133_test.js +9 -0
- package/tests/codeceptjs/issues/issue-gh-1158-2_test.js +10 -0
- package/tests/codeceptjs/issues/issue-gh-1158_test.js +8 -0
- package/tests/codeceptjs/issues/issue-gh-1164_test.js +9 -0
- package/tests/codeceptjs/issues/issue-gh-1171_test.js +11 -0
- package/tests/codeceptjs/issues/issue-gh-1211_test.js +17 -0
- package/tests/codeceptjs/issues/issue-gh-1257_test.js +11 -0
- package/tests/codeceptjs/issues/issue-gh-1272_test.js +21 -0
- package/tests/codeceptjs/issues/issue-gh-1330_test.js +8 -0
- package/tests/codeceptjs/issues/issue-gh-1338_test.js +18 -0
- package/tests/codeceptjs/issues/issue-gh-1347_test.js +8 -0
- package/tests/codeceptjs/issues/issue-gh-1364_test.js +13 -0
- package/tests/codeceptjs/issues/issue-gh-1367_test.js +11 -0
- package/tests/codeceptjs/issues/issue-gh-1383_test.js +9 -0
- package/tests/codeceptjs/issues/issue-gh-1384_test.js +9 -0
- package/tests/codeceptjs/issues/issue-gh-1410_test.js +13 -0
- package/tests/codeceptjs/issues/issue-gh-1422_test.js +9 -0
- package/tests/codeceptjs/issues/issue-gh-1431_test.js +12 -0
- package/tests/codeceptjs/issues/issue-gh-1439_test.js +12 -0
- package/tests/codeceptjs/issues/issue-gh-1452_test.js +10 -0
- package/tests/codeceptjs/issues/issue-gh-1453_test.js +18 -0
- package/tests/codeceptjs/issues/issue-gh-1461_test.js +14 -0
- package/tests/codeceptjs/issues/issue-gh-1463_test.js +9 -0
- package/tests/codeceptjs/issues/issue-gh-1471_test.js +17 -0
- package/tests/codeceptjs/issues/issue-gh-1485_test.js +13 -0
- package/tests/codeceptjs/issues/issue-gh-1491_test.js +9 -0
- package/tests/codeceptjs/issues/issue-gh-1525_test.js +9 -0
- package/tests/codeceptjs/issues/issue-gh-1536_test.js +12 -0
- package/tests/codeceptjs/issues/issue-gh-1538_test.js +10 -0
- package/tests/codeceptjs/issues/issue-gh-1541_test.js +8 -0
- package/tests/codeceptjs/issues/issue-gh-1559_test.js +15 -0
- package/tests/codeceptjs/issues/issue-gh-1562_test.js +12 -0
- package/tests/codeceptjs/issues/issue-gh-1586_test.js +15 -0
- package/tests/codeceptjs/issues/issue-gh-1636_test.js +9 -0
- package/tests/codeceptjs/issues/issue-gh-795_test.js +13 -0
- package/tests/codeceptjs/issues/issue-gh-810_test.js +52 -0
- package/tests/codeceptjs/issues/issue-gh-812_test.js +25 -0
- package/tests/codeceptjs/meta-schema_test.js +85 -0
- package/tests/codeceptjs/schemaloader_test.js +14 -0
- package/tests/codeceptjs/steps.d.ts +13 -0
- package/tests/codeceptjs/steps_file.js +4 -4
- package/tests/codeceptjs/test-config.js +3 -0
- package/tests/codeceptjs/themes_test.js +564 -0
- package/tests/docker-compose-local.yml +5 -0
- package/tests/docker-compose.yml +11 -19
- package/tests/fixtures/basic_person.json +2 -1
- package/tests/fixtures/definitions.json +22 -0
- package/tests/fixtures/nested_object.json +26 -0
- package/tests/fixtures/properties.json +20 -0
- package/tests/fixtures/some_types.json +32 -0
- package/tests/fixtures/validation.json +1347 -0
- package/tests/pages/_demo.html +475 -0
- package/tests/pages/advanced.html +1 -1
- package/tests/pages/anyof-2.html +91 -0
- package/tests/pages/anyof.html +82 -0
- package/tests/pages/array-anyof.html +145 -0
- package/tests/pages/array-checkboxes-infotext.html +55 -0
- package/tests/pages/array-checkboxes.html +5 -2
- package/tests/pages/array-choices.html +48 -0
- package/tests/pages/array-events-table.html +70 -0
- package/tests/pages/array-events.html +75 -0
- package/tests/pages/array-header-template.html +60 -0
- package/tests/pages/array-integers.html +5 -2
- package/tests/pages/array-multiselects.html +5 -2
- package/tests/pages/array-nested-arrays.html +5 -2
- package/tests/pages/array-numbers.html +5 -2
- package/tests/pages/array-objects.html +5 -2
- package/tests/pages/array-ratings.html +5 -2
- package/tests/pages/array-selectize-create.html +63 -0
- package/tests/pages/array-selectize.html +10 -8
- package/tests/pages/array-selects.html +5 -2
- package/tests/pages/array-strings.html +5 -2
- package/tests/pages/array-table-responsive.html +66 -0
- package/tests/pages/array-unique-items-sort.html +81 -0
- package/tests/pages/array.html +5 -2
- package/tests/pages/assets/autocomplete.css +1 -0
- package/tests/pages/assets/autocomplete.min.js +1 -0
- package/tests/pages/assets/pages.css +130 -0
- package/tests/pages/autocomplete.html +72 -0
- package/tests/pages/button-callbacks.html +79 -0
- package/tests/pages/button-icons.html +39 -0
- package/tests/pages/button_state_mode_1.html +35 -0
- package/tests/pages/button_state_mode_2.html +36 -0
- package/tests/pages/checkbox-labels.html +116 -0
- package/tests/pages/colorpicker-no-3rd-party.html +45 -0
- package/tests/pages/colorpicker-use-vanilla-picker.html +52 -0
- package/tests/pages/container-attributes.html +51 -0
- package/tests/pages/contains.html +39 -0
- package/tests/pages/core.html +14 -7
- package/tests/pages/datetime.html +78 -0
- package/tests/pages/dependentRequired.html +72 -0
- package/tests/pages/dependentSchemas.html +53 -0
- package/tests/pages/disable-button-in-object-editors.html +57 -0
- package/tests/pages/editor-show-validation-errors.html +54 -0
- package/tests/pages/enforce-const.html +168 -0
- package/tests/pages/error-messages.html +48 -0
- package/tests/pages/form-name.html +111 -0
- package/tests/pages/grid-strict.html +10 -13
- package/tests/pages/grid.html +4 -7
- package/tests/pages/if-else.html +58 -0
- package/tests/pages/if-then-else-allOf.html +118 -0
- package/tests/pages/if-then-else-disable-fields.html +70 -0
- package/tests/pages/if-then-else.html +65 -0
- package/tests/pages/if-then.html +58 -0
- package/tests/pages/inheritance.html +80 -0
- package/tests/pages/integer.html +17 -10
- package/tests/pages/issues/_template.html +50 -0
- package/tests/pages/issues/issue-gh-1133.html +64 -0
- package/tests/pages/issues/issue-gh-1158-2.html +189 -0
- package/tests/pages/issues/issue-gh-1158.html +50 -0
- package/tests/pages/issues/issue-gh-1164.html +71 -0
- package/tests/pages/issues/issue-gh-1165.html +63 -0
- package/tests/pages/issues/issue-gh-1165.json +8 -0
- package/tests/pages/issues/issue-gh-1171.html +39 -0
- package/tests/pages/issues/issue-gh-1211.html +1022 -0
- package/tests/pages/issues/issue-gh-1233-failing.html +46 -0
- package/tests/pages/issues/issue-gh-1233-passing.html +49 -0
- package/tests/pages/issues/issue-gh-1257.html +77 -0
- package/tests/pages/issues/issue-gh-1272.html +167 -0
- package/tests/pages/issues/issue-gh-1330.html +52 -0
- package/tests/pages/issues/issue-gh-1338.html +74 -0
- package/tests/pages/issues/issue-gh-1347.html +142 -0
- package/tests/pages/issues/issue-gh-1364.html +64 -0
- package/tests/pages/issues/issue-gh-1367.html +49 -0
- package/tests/pages/issues/issue-gh-1383.html +31 -0
- package/tests/pages/issues/issue-gh-1383.json +14 -0
- package/tests/pages/issues/issue-gh-1384.html +31 -0
- package/tests/pages/issues/issue-gh-1384.json +36 -0
- package/tests/pages/issues/issue-gh-1410.html +57 -0
- package/tests/pages/issues/issue-gh-1422.html +68 -0
- package/tests/pages/issues/issue-gh-1431.html +49 -0
- package/tests/pages/issues/issue-gh-1439.html +69 -0
- package/tests/pages/issues/issue-gh-1452.html +98 -0
- package/tests/pages/issues/issue-gh-1453.html +45 -0
- package/tests/pages/issues/issue-gh-1461.html +55 -0
- package/tests/pages/issues/issue-gh-1463.html +41 -0
- package/tests/pages/issues/issue-gh-1466.html +63 -0
- package/tests/pages/issues/issue-gh-1471.html +49 -0
- package/tests/pages/issues/issue-gh-1485.html +59 -0
- package/tests/pages/issues/issue-gh-1491.html +59 -0
- package/tests/pages/issues/issue-gh-1525.html +62 -0
- package/tests/pages/issues/issue-gh-1536.html +55 -0
- package/tests/pages/issues/issue-gh-1538.html +56 -0
- package/tests/pages/issues/issue-gh-1541.html +51 -0
- package/tests/pages/issues/issue-gh-1541.json +9 -0
- package/tests/pages/issues/issue-gh-1559.html +68 -0
- package/tests/pages/issues/issue-gh-1562.html +170 -0
- package/tests/pages/issues/issue-gh-1586.html +48 -0
- package/tests/pages/issues/issue-gh-1636.html +52 -0
- package/tests/pages/issues/issue-gh-795.html +58 -0
- package/tests/pages/issues/issue-gh-810.html +149 -0
- package/tests/pages/issues/issue-gh-812.html +113 -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/keep_only_existing_values.html +81 -0
- package/tests/pages/load-events.html +61 -0
- package/tests/pages/maxContains.html +40 -0
- package/tests/pages/meta-schema.html +793 -0
- package/tests/pages/meta_schema.json +740 -0
- package/tests/pages/minContains.html +40 -0
- package/tests/pages/number.html +53 -6
- package/tests/pages/object-case-sensitive-property-search-false.html +42 -0
- package/tests/pages/object-case-sensitive-property-search-true.html +42 -0
- package/tests/pages/object-no-additional-properties.html +68 -0
- package/tests/pages/object-no-duplicated-id.html +70 -0
- package/tests/pages/object-required-properties.html +56 -20
- package/tests/pages/object-show-opt-in.html +111 -0
- package/tests/pages/object-with-dependencies-array.html +58 -0
- package/tests/pages/object-with-dependencies.html +62 -0
- package/tests/pages/object.html +5 -3
- package/tests/pages/oneof-2.html +91 -0
- package/tests/pages/oneof.html +105 -0
- package/tests/pages/opt-in-widget.html +134 -0
- package/tests/pages/option-dependencies.html +107 -0
- package/tests/pages/option-no_default_values.html +60 -0
- package/tests/pages/per-editor-options.html +44 -0
- package/tests/pages/placeholder-options.html +57 -0
- package/tests/pages/programmatic-changes.html +121 -0
- package/tests/pages/prompt-paste-max-length-reached.html +51 -0
- package/tests/pages/purify.html +66 -0
- package/tests/pages/range.html +62 -0
- package/tests/pages/read-only.html +60 -8
- package/tests/pages/ready.html +44 -0
- package/tests/pages/references.html +168 -0
- package/tests/pages/remove-false-properties.html +85 -0
- package/tests/pages/select-values.html +91 -0
- package/tests/pages/select.html +4 -3
- package/tests/pages/show-validation-errors.html +73 -0
- package/tests/pages/starrating.html +86 -0
- package/tests/pages/stepper-manual.html +59 -0
- package/tests/pages/stepper.html +61 -0
- package/tests/pages/string-ace-editor.html +7 -3
- package/tests/pages/string-cleave.html +48 -0
- package/tests/pages/string-custom-attributes.html +9 -6
- package/tests/pages/string-formats.html +54 -0
- package/tests/pages/string-formats2.html +59 -0
- package/tests/pages/{array-move-events.html → string-jodit-editor.html} +21 -29
- package/tests/pages/string-sceditor.html +9 -7
- package/tests/pages/string-simplemde-editor.html +83 -0
- package/tests/pages/switcher-option.html +69 -0
- package/tests/pages/table.html +4 -2
- package/tests/pages/tabs.html +1 -1
- package/tests/pages/themes.html +517 -0
- package/tests/pages/title-hidden.html +75 -0
- package/tests/pages/translate-property.html +248 -0
- package/tests/pages/urn.html +98 -0
- package/tests/pages/use-name-attributes.html +207 -0
- package/tests/pages/uuid.html +113 -0
- package/tests/pages/validation-messages.json +705 -0
- package/tests/pages/validation.html +20 -730
- package/tests/unit/.eslintrc +8 -0
- package/tests/unit/core.spec.js +320 -0
- package/tests/unit/defaults.spec.js +40 -0
- package/tests/unit/editor.spec.js +172 -0
- package/tests/unit/editors/array.spec.js +87 -0
- package/tests/unit/editors/object.spec.js +81 -0
- package/tests/unit/editors/table.spec.js +93 -0
- package/tests/unit/readme.md +35 -0
- package/tests/unit/schemaloader.spec.js +576 -0
- package/tests/unit/validator.spec.js +104 -0
- package/tests/unit/validators/ip-validator.spec.js +62 -0
- package/Gruntfile.js +0 -228
- package/dist/css/jsoneditor.min.css +0 -1
- package/dist/jsoneditor.js.map +0 -1
- package/dist/jsoneditor.min.js +0 -19
- package/dist/jsoneditor.min.js.map +0 -1
- package/src/class.js +0 -68
- package/src/editors/rating.js +0 -152
- package/src/ie9.js +0 -51
- package/src/intro.js +0 -23
- package/src/jquery.js +0 -64
- package/src/outro.js +0 -2
- package/src/themes/jsoneditor.barebones-theme.js +0 -60
package/README.md
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
JSON Editor
|
|
2
2
|
===========
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
> **🔧 Maintenance Mode Notice**
|
|
5
|
+
>
|
|
6
|
+
> This library is now in maintenance mode. While it remains stable and functional, active development has moved to [Jedison](https://github.com/germanbisurgi/jedison).
|
|
7
|
+
>
|
|
8
|
+
> We will continue to:
|
|
9
|
+
> - Accept and review community pull requests
|
|
10
|
+
> - Address critical bugs and security issues
|
|
11
|
+
> - Keep the library functional for existing users
|
|
12
|
+
>
|
|
13
|
+
> For new projects or those seeking active development, consider using [Jedison](https://github.com/germanbisurgi/jedison).
|
|
14
|
+
|
|
15
|
+
[](https://github.com/json-editor/json-editor/actions)
|
|
16
|
+
|
|
17
|
+
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).
|
|
6
18
|
Some pull requests added from the original repo.
|
|
7
19
|
|
|
8
20
|

|
|
9
21
|
|
|
10
|
-
JSON Editor takes a JSON Schema and uses it to generate an HTML form.
|
|
11
|
-
It has full support for JSON Schema version 3 and 4 and can integrate with several popular CSS frameworks (bootstrap,
|
|
22
|
+
JSON Editor takes a JSON Schema and uses it to generate an HTML form.
|
|
23
|
+
It has full support for JSON Schema version 3 and 4 and can integrate with several popular CSS frameworks (bootstrap, spectre, tailwind).
|
|
24
|
+
|
|
25
|
+
Take a look at this [example](https://json-editor.github.io/json-editor/form-submission.html) for a simple form submission case study.
|
|
26
|
+
### Online Demo
|
|
12
27
|
|
|
13
28
|
Check out an interactive demo: https://json-editor.github.io/json-editor/
|
|
14
29
|
|
|
15
|
-
Or the JSON-Editor Interactive Playground: https://pmk65.github.io/jedemov2/dist/demo.html
|
|
30
|
+
Or the JSON-Editor Interactive Playground: https://pmk65.github.io/jedemov2/dist/demo.html
|
|
16
31
|
|
|
17
32
|
Install
|
|
18
33
|
-----------------
|
|
@@ -27,7 +42,7 @@ Using a CDN
|
|
|
27
42
|
|
|
28
43
|
You can also access older releases from CDN, using the landing page: https://www.jsdelivr.com/package/npm/@json-editor/json-editor
|
|
29
44
|
|
|
30
|
-
For local usage download the [production version](https://cdn.jsdelivr.net/npm/@json-editor/json-editor@latest/dist/jsoneditor.
|
|
45
|
+
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)
|
|
31
46
|
|
|
32
47
|
Requirements
|
|
33
48
|
-----------------
|
|
@@ -39,16 +54,21 @@ JSON Editor has no dependencies. It only needs a modern browser (tested in Chrom
|
|
|
39
54
|
The following are not required, but can improve the style and usability of JSON Editor when present.
|
|
40
55
|
|
|
41
56
|
* A compatible JS template engine (Mustache, Underscore, Hogan, Handlebars, Lodash, Swig, Markup, or EJS)
|
|
42
|
-
* A compatible CSS framework for styling (
|
|
43
|
-
* A compatible icon library (
|
|
57
|
+
* A compatible CSS framework for styling (Spectre, Tailwind, Bootstrap4)
|
|
58
|
+
* A compatible icon library (Spectre, jQueryUI, Font Awesome 3/4/5)
|
|
44
59
|
* [SCEditor](http://www.sceditor.com/) for WYSIWYG editing of HTML or BBCode content
|
|
45
60
|
* [SimpleMDE](https://simplemde.com/) for editing of Markdown content
|
|
46
61
|
* [Ace Editor](http://ace.c9.io/) for editing code
|
|
62
|
+
* [Jodit](https://xdsoft.net/jodit/) Open Source WYSIWYG editor
|
|
63
|
+
* [Autocomplete](https://autocomplete.trevoreyre.com/#/javascript-component) Accessible autocomplete component
|
|
64
|
+
* [Choices](https://github.com/jshjohnson/Choices) for nicer Select & Array boxes
|
|
47
65
|
* [Select2](http://ivaynberg.github.io/select2/) for nicer Select boxes
|
|
48
66
|
* [Selectize](https://selectize.github.io/selectize.js/) for nicer Select & Array boxes
|
|
49
67
|
* [Flatpickr](https://flatpickr.js.org/) lightweight and powerful datetime picker
|
|
50
68
|
* [Signature Pad](https://github.com/szimek/signature_pad) HTML5 canvas based smooth signature drawing
|
|
69
|
+
* [Vanilla Picker](https://vanilla-picker.js.org/) A simple, easy to use vanilla JS color picker with alpha selection
|
|
51
70
|
* [Cleave.js](https://github.com/nosir/cleave.js) for formatting your **<input/>** content while you are typing
|
|
71
|
+
* [IMask.js](https://imask.js.org/) vanilla javascript input mask
|
|
52
72
|
* [math.js](http://mathjs.org/) for more accurate floating point math (multipleOf, divisibleBy, etc.)
|
|
53
73
|
* [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.)
|
|
54
74
|
|
|
@@ -62,9 +82,12 @@ If you learn best by example, check these out:
|
|
|
62
82
|
* Advanced Usage Example - https://json-editor.github.io/json-editor/advanced.html
|
|
63
83
|
* CSS Integration Example - https://json-editor.github.io/json-editor/css_integration.html
|
|
64
84
|
* Base64 Editor Example (Muiltple Upload) - https://json-editor.github.io/json-editor/multiple_upload_base64.html
|
|
85
|
+
* Choices Editor Example - https://json-editor.github.io/json-editor/choices.html
|
|
65
86
|
* Cleave.js Editor Example - https://json-editor.github.io/json-editor/cleave.html
|
|
87
|
+
* Colorpicker Editor Example - https://json-editor.github.io/json-editor/colorpicker.html
|
|
66
88
|
* Datetime Editor Example - https://json-editor.github.io/json-editor/datetime.html
|
|
67
|
-
* DescribedBy Hyperlink Editor Example - https://json-editor.github.io/json-editor/describedby.html
|
|
89
|
+
* DescribedBy Hyperlink Editor Example - https://json-editor.github.io/json-editor/describedby.html
|
|
90
|
+
* iMask.js Editor Example - https://json-editor.github.io/json-editor/imask.html
|
|
68
91
|
* Radio Button JSON Editor Example - https://json-editor.github.io/json-editor/radio.html
|
|
69
92
|
* Recursive JSON Editor Example - https://json-editor.github.io/json-editor/recursive.html
|
|
70
93
|
* Select2 Editor Example - https://json-editor.github.io/json-editor/select2.html
|
|
@@ -73,16 +96,18 @@ If you learn best by example, check these out:
|
|
|
73
96
|
* Star Rating Editor Example - https://json-editor.github.io/json-editor/starrating.html
|
|
74
97
|
* Upload Editor Example - https://json-editor.github.io/json-editor/upload.html
|
|
75
98
|
* WYSIWYG Editor Example - https://json-editor.github.io/json-editor/wysiwyg.html
|
|
99
|
+
* Meta schema (schema builder) Example - https://json-editor.github.io/json-editor/meta-schema.html
|
|
76
100
|
|
|
101
|
+
More examples can be found at the [JSON-Editor Interactive Playground](https://pmk65.github.io/jedemov2/dist/demo.html)
|
|
77
102
|
|
|
78
103
|
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.
|
|
79
104
|
|
|
80
105
|
### Initialize
|
|
81
106
|
|
|
82
107
|
```js
|
|
83
|
-
|
|
108
|
+
const element = document.getElementById('editor_holder');
|
|
84
109
|
|
|
85
|
-
|
|
110
|
+
const editor = new JSONEditor(element, options);
|
|
86
111
|
```
|
|
87
112
|
|
|
88
113
|
#### Options
|
|
@@ -91,12 +116,12 @@ Options can be set globally or on a per-instance basis during instantiation.
|
|
|
91
116
|
|
|
92
117
|
```js
|
|
93
118
|
// Set an option globally
|
|
94
|
-
JSONEditor.defaults.options.theme = '
|
|
119
|
+
JSONEditor.defaults.options.theme = 'bootstrap4';
|
|
95
120
|
|
|
96
121
|
// Set an option during instantiation
|
|
97
|
-
|
|
122
|
+
const editor = new JSONEditor(element, {
|
|
98
123
|
//...
|
|
99
|
-
theme: '
|
|
124
|
+
theme: 'bootstrap4'
|
|
100
125
|
});
|
|
101
126
|
```
|
|
102
127
|
|
|
@@ -126,6 +151,16 @@ Here are all the available options:
|
|
|
126
151
|
<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>
|
|
127
152
|
<td><code>false</code></td>
|
|
128
153
|
</tr>
|
|
154
|
+
<tr>
|
|
155
|
+
<td>ajax_cache_responses</td>
|
|
156
|
+
<td>If <code>true</code>, JSON Editor will cache external URLs' schemas in <code>localStorage</code> to avoid subsequent ajax calls.</td>
|
|
157
|
+
<td><code>false</code></td>
|
|
158
|
+
</tr>
|
|
159
|
+
<tr>
|
|
160
|
+
<td>ajax_cache_buster</td>
|
|
161
|
+
<td>If <code>ajax_cache_responses</code> is enabled, use this string to invalidate stale caches. E.g., this value should be changed when schemas are updated.</td>
|
|
162
|
+
<td>Current date in simplied ISO-8601 format (e.g., "2011-10-05" for October 5, 2011).</td>
|
|
163
|
+
</tr>
|
|
129
164
|
<tr>
|
|
130
165
|
<td>compact</td>
|
|
131
166
|
<td>If <code>true</code>, the label will not be displayed/added.</td>
|
|
@@ -141,6 +176,16 @@ Here are all the available options:
|
|
|
141
176
|
<td>If <code>true</code>, remove all "delete row" buttons from arrays.</td>
|
|
142
177
|
<td><code>false</code></td>
|
|
143
178
|
</tr>
|
|
179
|
+
<tr>
|
|
180
|
+
<td>disable_array_delete_all_rows</td>
|
|
181
|
+
<td>If <code>true</code>, remove all "delete all rows" buttons from arrays.</td>
|
|
182
|
+
<td><code>false</code></td>
|
|
183
|
+
</tr>
|
|
184
|
+
<tr>
|
|
185
|
+
<td>disable_array_delete_last_row</td>
|
|
186
|
+
<td>If <code>true</code>, remove all "delete last row" buttons from arrays.</td>
|
|
187
|
+
<td><code>false</code></td>
|
|
188
|
+
</tr>
|
|
144
189
|
<tr>
|
|
145
190
|
<td>disable_array_reorder</td>
|
|
146
191
|
<td>If <code>true</code>, remove all "move up" and "move down" buttons from arrays.</td>
|
|
@@ -182,9 +227,14 @@ Here are all the available options:
|
|
|
182
227
|
<td>The icon library to use for the editor. See the <strong>CSS Integration</strong> section below for more info.</td>
|
|
183
228
|
<td><code>null</code></td>
|
|
184
229
|
</tr>
|
|
230
|
+
<tr>
|
|
231
|
+
<td>remove_button_labels</td>
|
|
232
|
+
<td>Display only icons in buttons. This works only if iconlib is set.</td>
|
|
233
|
+
<td><code>false</code></td>
|
|
234
|
+
</tr>
|
|
185
235
|
<tr>
|
|
186
236
|
<td>no_additional_properties</td>
|
|
187
|
-
<td>If <code>true</code>, objects can only contain properties defined with the <code>properties</code> keyword
|
|
237
|
+
<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>
|
|
188
238
|
<td><code>false</code></td>
|
|
189
239
|
</tr>
|
|
190
240
|
<tr>
|
|
@@ -202,6 +252,11 @@ Here are all the available options:
|
|
|
202
252
|
<td>If <code>true</code>, makes oneOf copy properties over when switching.</td>
|
|
203
253
|
<td><code>true</code></td>
|
|
204
254
|
</tr>
|
|
255
|
+
<tr>
|
|
256
|
+
<td>keep_only_existing_values</td>
|
|
257
|
+
<td>If <code>true</code>, copy only existing properties over when switching.</td>
|
|
258
|
+
<td><code>false</code></td>
|
|
259
|
+
</tr>
|
|
205
260
|
<tr>
|
|
206
261
|
<td>schema</td>
|
|
207
262
|
<td>A valid JSON Schema to use for the editor. Version 3 and Version 4 of the draft specification are supported.</td>
|
|
@@ -242,6 +297,61 @@ Here are all the available options:
|
|
|
242
297
|
<td>If <code>true</code>, displays a dialog box with a confirmation message before node deletion.</td>
|
|
243
298
|
<td><code>true</code></td>
|
|
244
299
|
</tr>
|
|
300
|
+
<tr>
|
|
301
|
+
<td>object_layout</td>
|
|
302
|
+
<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>
|
|
303
|
+
<td><code>normal</code></td>
|
|
304
|
+
</tr>
|
|
305
|
+
<tr>
|
|
306
|
+
<td>enum_source_value_auto_select</td>
|
|
307
|
+
<td>Preserve value at Move Up or Down.(No value is selected automatically upon deletion.)</td>
|
|
308
|
+
<td><code>true</code></td>
|
|
309
|
+
</tr>
|
|
310
|
+
<tr>
|
|
311
|
+
<td>max_depth</td>
|
|
312
|
+
<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>
|
|
313
|
+
<td><code>0</code></td>
|
|
314
|
+
</tr>
|
|
315
|
+
<tr>
|
|
316
|
+
<td>use_default_values</td>
|
|
317
|
+
<td>If true default values based on the "type" of the property will be used</td>
|
|
318
|
+
<td><code>true</code></td>
|
|
319
|
+
</tr>
|
|
320
|
+
<tr>
|
|
321
|
+
<td>urn_resolver</td>
|
|
322
|
+
<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>
|
|
323
|
+
<td><code>false</code></td>
|
|
324
|
+
</tr>
|
|
325
|
+
<tr>
|
|
326
|
+
<td>use_name_attributes</td>
|
|
327
|
+
<td>If <code>true</code>, control inputs <code>name</code> attributes will be set.</td>
|
|
328
|
+
<td><code>true</code></td>
|
|
329
|
+
</tr>
|
|
330
|
+
<tr>
|
|
331
|
+
<td>button_state_mode</td>
|
|
332
|
+
<td>If <code>1</code>, inactive buttons are hidden. If <code>2</code>, inactive buttons are disabled.</td>
|
|
333
|
+
<td><code>1</code></td>
|
|
334
|
+
</tr>
|
|
335
|
+
<tr>
|
|
336
|
+
<td>case_sensitive_property_search</td>
|
|
337
|
+
<td>This property controls whether property searches in an object editor are case-sensitive</td>
|
|
338
|
+
<td><code>true</code></td>
|
|
339
|
+
</tr>
|
|
340
|
+
<tr>
|
|
341
|
+
<td>prompt_paste_max_length_reached</td>
|
|
342
|
+
<td>If <code>true</code>, an alert will be displayed when pasting a value in an input that exceeded maxLength</td>
|
|
343
|
+
<td><code>false</code></td>
|
|
344
|
+
</tr>
|
|
345
|
+
<tr>
|
|
346
|
+
<td>enforce_const</td>
|
|
347
|
+
<td>When set to <code>true</code>, the schema <code>const</code> will serve as the default value, and the editor will prevent any changes to it.</td>
|
|
348
|
+
<td><code>false</code></td>
|
|
349
|
+
</tr>
|
|
350
|
+
<tr>
|
|
351
|
+
<td>opt_in_widget</td>
|
|
352
|
+
<td>Which widget should be used for opt-in inputs. Possible values are <code>'checkbox'</code> and <code>'switch'</code></td>
|
|
353
|
+
<td><code>'checkbox'</code></td>
|
|
354
|
+
</tr>
|
|
245
355
|
</tbody>
|
|
246
356
|
</table>
|
|
247
357
|
|
|
@@ -249,7 +359,7 @@ __*Note__ If the `ajax` property is `true` and JSON Editor needs to fetch an ext
|
|
|
249
359
|
Listen for the `ready` event before calling them.
|
|
250
360
|
|
|
251
361
|
```js
|
|
252
|
-
editor.on('ready',
|
|
362
|
+
editor.on('ready',() => {
|
|
253
363
|
// Now the api methods will be available
|
|
254
364
|
editor.validate();
|
|
255
365
|
});
|
|
@@ -260,7 +370,7 @@ editor.on('ready',function() {
|
|
|
260
370
|
```js
|
|
261
371
|
editor.setValue({name: "John Smith"});
|
|
262
372
|
|
|
263
|
-
|
|
373
|
+
const value = editor.getValue();
|
|
264
374
|
console.log(value.name) // Will log "John Smith"
|
|
265
375
|
```
|
|
266
376
|
|
|
@@ -268,17 +378,16 @@ Instead of getting/setting the value of the entire editor, you can also work on
|
|
|
268
378
|
|
|
269
379
|
```js
|
|
270
380
|
// Get a reference to a node within the editor
|
|
271
|
-
|
|
381
|
+
const name = editor.getEditor('root.name');
|
|
272
382
|
|
|
273
383
|
// `getEditor` will return null if the path is invalid
|
|
274
|
-
if(name) {
|
|
384
|
+
if (name) {
|
|
275
385
|
name.setValue("John Smith");
|
|
276
386
|
|
|
277
387
|
console.log(name.getValue());
|
|
278
388
|
}
|
|
279
389
|
```
|
|
280
390
|
|
|
281
|
-
|
|
282
391
|
### Validate
|
|
283
392
|
|
|
284
393
|
When feasible, JSON Editor won't let users enter invalid data. This is done by
|
|
@@ -290,9 +399,9 @@ You can use the `validate` method to check if the data is valid or not.
|
|
|
290
399
|
|
|
291
400
|
```javascript
|
|
292
401
|
// Validate the editor's current value against the schema
|
|
293
|
-
|
|
402
|
+
const errors = editor.validate();
|
|
294
403
|
|
|
295
|
-
if(errors.length) {
|
|
404
|
+
if (errors.length) {
|
|
296
405
|
// errors is an array of objects, each with a `path`, `property`, and `message` parameter
|
|
297
406
|
// `property` is the schema keyword that triggered the validation error (e.g. "minLength")
|
|
298
407
|
// `path` is a dot separated path into the JSON object (e.g. "root.path.to.field")
|
|
@@ -309,19 +418,25 @@ If you want to use a different value, you can pass it in as a parameter.
|
|
|
309
418
|
|
|
310
419
|
```javascript
|
|
311
420
|
// Validate an arbitrary value against the editor's schema
|
|
312
|
-
|
|
421
|
+
const errors = editor.validate({
|
|
313
422
|
value: {
|
|
314
423
|
to: "test"
|
|
315
424
|
}
|
|
316
425
|
});
|
|
317
426
|
```
|
|
318
427
|
|
|
428
|
+
Display validation errors on demand
|
|
429
|
+
|
|
430
|
+
```javascript
|
|
431
|
+
editor.showValidationErrors();
|
|
432
|
+
```
|
|
433
|
+
|
|
319
434
|
### Listen for Changes
|
|
320
435
|
|
|
321
436
|
The `change` event is fired whenever the editor's value changes.
|
|
322
437
|
|
|
323
438
|
```javascript
|
|
324
|
-
editor.on('change',
|
|
439
|
+
editor.on('change',() => {
|
|
325
440
|
// Do something
|
|
326
441
|
});
|
|
327
442
|
|
|
@@ -331,7 +446,7 @@ editor.off('change',function_reference);
|
|
|
331
446
|
You can also watch a specific field for changes:
|
|
332
447
|
|
|
333
448
|
```javascript
|
|
334
|
-
editor.watch('path.to.field',
|
|
449
|
+
editor.watch('path.to.field',() => {
|
|
335
450
|
// Do something
|
|
336
451
|
});
|
|
337
452
|
|
|
@@ -341,17 +456,34 @@ editor.unwatch('path.to.field',function_reference);
|
|
|
341
456
|
Or watch all fields (Similar to the "onchange" event, but tracks the field changed)
|
|
342
457
|
|
|
343
458
|
```javascript
|
|
344
|
-
|
|
345
|
-
console.log(
|
|
459
|
+
const watcherCallback = function (path) {
|
|
460
|
+
console.log(`field with path: [${path}] changed to [${JSON.stringify(this.getEditor(path).getValue())}]`);
|
|
346
461
|
// Do something
|
|
347
462
|
}
|
|
348
|
-
for (
|
|
463
|
+
for (let key in editor.editors) {
|
|
349
464
|
if (editor.editors.hasOwnProperty(key) && key !== 'root') {
|
|
350
465
|
editor.watch(key, watcherCallback.bind(editor, key));
|
|
351
466
|
}
|
|
352
467
|
}
|
|
353
468
|
```
|
|
354
469
|
|
|
470
|
+
There are also `add` and `switch` events to track changes.
|
|
471
|
+
The `add` event fires when a new object property has just been added.
|
|
472
|
+
|
|
473
|
+
```javascript
|
|
474
|
+
editor.on('add',(property) => {
|
|
475
|
+
// Do something
|
|
476
|
+
});
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
The `switch` event fires when the type of one of the object's properties is changed by a type switch on the form.
|
|
480
|
+
|
|
481
|
+
```javascript
|
|
482
|
+
editor.on('switch',(property) => {
|
|
483
|
+
// Do something
|
|
484
|
+
});
|
|
485
|
+
```
|
|
486
|
+
|
|
355
487
|
### Enable and Disable the Editor
|
|
356
488
|
|
|
357
489
|
This lets you disable editing for the entire form or part of the form.
|
|
@@ -371,6 +503,12 @@ editor.getEditor('root.location').enable();
|
|
|
371
503
|
|
|
372
504
|
// Check if form is currently enabled
|
|
373
505
|
if(editor.isEnabled()) alert("It's editable!");
|
|
506
|
+
|
|
507
|
+
// Activate part of the form
|
|
508
|
+
editor.activate();
|
|
509
|
+
|
|
510
|
+
// Deactivate part of the form
|
|
511
|
+
editor.deactivate();
|
|
374
512
|
```
|
|
375
513
|
|
|
376
514
|
### Destroy
|
|
@@ -389,9 +527,16 @@ The currently supported themes are:
|
|
|
389
527
|
|
|
390
528
|
* barebones
|
|
391
529
|
* html (the default)
|
|
392
|
-
* bootstrap2
|
|
393
530
|
* bootstrap3
|
|
394
531
|
* bootstrap4
|
|
532
|
+
* bootstrap5
|
|
533
|
+
* spectre
|
|
534
|
+
* tailwind
|
|
535
|
+
|
|
536
|
+
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.
|
|
537
|
+
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.
|
|
538
|
+
|
|
539
|
+
* bootstrap2
|
|
395
540
|
* foundation3
|
|
396
541
|
* foundation4
|
|
397
542
|
* foundation5
|
|
@@ -405,15 +550,15 @@ This default can be changed by setting the `JSONEditor.defaults.options.theme` v
|
|
|
405
550
|
If you want to specify your own styles with CSS, you can use `barebones`, which includes almost no classes or inline styles.
|
|
406
551
|
|
|
407
552
|
```javascript
|
|
408
|
-
JSONEditor.defaults.options.theme = '
|
|
553
|
+
JSONEditor.defaults.options.theme = 'spectre';
|
|
409
554
|
```
|
|
410
555
|
|
|
411
556
|
You can override this default on a per-instance basis by passing a `theme` parameter in when initializing:
|
|
412
557
|
|
|
413
558
|
```js
|
|
414
|
-
|
|
559
|
+
const editor = new JSONEditor(element,{
|
|
415
560
|
schema: schema,
|
|
416
|
-
theme: '
|
|
561
|
+
theme: 'tailwind'
|
|
417
562
|
});
|
|
418
563
|
```
|
|
419
564
|
|
|
@@ -423,24 +568,22 @@ JSON Editor also supports several popular icon libraries. The icon library must
|
|
|
423
568
|
|
|
424
569
|
The supported icon libs are:
|
|
425
570
|
|
|
426
|
-
* bootstrap2 (glyphicons)
|
|
427
|
-
* bootstrap3 (glyphicons)
|
|
428
|
-
* foundation2
|
|
429
|
-
* foundation3
|
|
430
571
|
* jqueryui
|
|
431
572
|
* fontawesome3
|
|
432
573
|
* fontawesome4
|
|
433
574
|
* fontawesome5
|
|
434
|
-
*
|
|
575
|
+
* openiconic
|
|
576
|
+
* spectre
|
|
577
|
+
* bootstrap
|
|
435
578
|
|
|
436
579
|
By default, no icons are used. Just like the CSS theme, you can set the icon lib globally or when initializing:
|
|
437
580
|
|
|
438
581
|
```js
|
|
439
582
|
// Set the global default
|
|
440
|
-
JSONEditor.defaults.options.iconlib = "
|
|
583
|
+
JSONEditor.defaults.options.iconlib = "spectre";
|
|
441
584
|
|
|
442
585
|
// Set the icon lib during initialization
|
|
443
|
-
|
|
586
|
+
const editor = new JSONEditor(element,{
|
|
444
587
|
schema: schema,
|
|
445
588
|
iconlib: "fontawesome4"
|
|
446
589
|
});
|
|
@@ -452,16 +595,16 @@ It's possible to create your own custom themes and/or icon libs as well. Look a
|
|
|
452
595
|
JSON Schema Support
|
|
453
596
|
-----------------
|
|
454
597
|
|
|
455
|
-
JSON Editor fully supports version 3 and 4 of the JSON Schema [core][core] and [validation][validation] specifications.
|
|
598
|
+
JSON Editor fully supports version 3 and 4 of the JSON Schema [core][core] and [validation][validation] specifications.
|
|
456
599
|
Some of The [hyper-schema][hyper] specification is supported as well.
|
|
457
600
|
|
|
458
601
|
[core]: http://json-schema.org/latest/json-schema-core.html
|
|
459
602
|
[validation]: http://json-schema.org/latest/json-schema-validation.html
|
|
460
|
-
[hyper]:
|
|
603
|
+
[hyper]: https://json-schema.org/draft-07/json-hyper-schema-release-notes
|
|
461
604
|
|
|
462
605
|
### $ref and definitions
|
|
463
606
|
|
|
464
|
-
JSON Editor supports schema references to external URLs and local definitions. Here's an example
|
|
607
|
+
JSON Editor supports schema references to external URLs and local definitions as well as JSON Pointers. Here's an example:
|
|
465
608
|
|
|
466
609
|
```json
|
|
467
610
|
{
|
|
@@ -473,6 +616,9 @@ JSON Editor supports schema references to external URLs and local definitions.
|
|
|
473
616
|
},
|
|
474
617
|
"location": {
|
|
475
618
|
"$ref": "http://mydomain.com/geo.json"
|
|
619
|
+
},
|
|
620
|
+
"birthday": {
|
|
621
|
+
"$ref": "http://mydomain.com/person.json#/definitions/birthdate"
|
|
476
622
|
}
|
|
477
623
|
},
|
|
478
624
|
"definitions": {
|
|
@@ -496,8 +642,8 @@ Self-referential $refs are supported. Check out `examples/recursive.html` for u
|
|
|
496
642
|
|
|
497
643
|
The `links` keyword from the hyper-schema specification can be used to add links to related documents.
|
|
498
644
|
|
|
499
|
-
JSON Editor will use the `mediaType` property of the links to determine how best to display them.
|
|
500
|
-
Image, audio, and video links will display the media inline as well as providing a text link.
|
|
645
|
+
JSON Editor will use the `mediaType` property of the links to determine how best to display them.
|
|
646
|
+
Image, audio, and video links will display the media inline as well as providing a text link.
|
|
501
647
|
|
|
502
648
|
Here are a couple examples:
|
|
503
649
|
|
|
@@ -550,6 +696,52 @@ Show a video preview (using HTML5 video)
|
|
|
550
696
|
The `href` property is a template that gets re-evaluated every time the value changes.
|
|
551
697
|
The variable `self` is always available. Look at the __Dependencies__ section below for how to include other fields or use a custom template engine.
|
|
552
698
|
|
|
699
|
+
### if-then-else
|
|
700
|
+
The if-then-else keywords are used to express conditional validation logic based on the evaluation of a specified condition. The if keyword defines a condition, and depending on whether it evaluates to true or false, the schema specified under either the then or else keywords will be applied.
|
|
701
|
+
|
|
702
|
+
```json
|
|
703
|
+
{
|
|
704
|
+
"type": "object",
|
|
705
|
+
"properties": {
|
|
706
|
+
"street_address": {
|
|
707
|
+
"type": "string"
|
|
708
|
+
},
|
|
709
|
+
"country": {
|
|
710
|
+
"type": "string",
|
|
711
|
+
"default": "United States of America",
|
|
712
|
+
"enum": [
|
|
713
|
+
"United States of America",
|
|
714
|
+
"Canada"
|
|
715
|
+
]
|
|
716
|
+
},
|
|
717
|
+
"postal_code": {
|
|
718
|
+
"type": "string"
|
|
719
|
+
}
|
|
720
|
+
},
|
|
721
|
+
"if": {
|
|
722
|
+
"properties": {
|
|
723
|
+
"country": {
|
|
724
|
+
"const": "United States of America"
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
},
|
|
728
|
+
"then": {
|
|
729
|
+
"properties": {
|
|
730
|
+
"postal_code": {
|
|
731
|
+
"pattern": "[0-9]{5}(-[0-9]{4})?"
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
},
|
|
735
|
+
"else": {
|
|
736
|
+
"properties": {
|
|
737
|
+
"postal_code": {
|
|
738
|
+
"pattern": "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]"
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
```
|
|
744
|
+
|
|
553
745
|
### Property Ordering
|
|
554
746
|
|
|
555
747
|
There is no way to specify property ordering in JSON Schema (although this may change in v5 of the spec).
|
|
@@ -616,7 +808,6 @@ JSON Editor uses HTML5 input types, so some of these may render as basic text in
|
|
|
616
808
|
|
|
617
809
|
* color
|
|
618
810
|
* date
|
|
619
|
-
* datetime
|
|
620
811
|
* datetime-local
|
|
621
812
|
* email
|
|
622
813
|
* month
|
|
@@ -646,7 +837,8 @@ Here is an example that will show a color picker in browsers that support it:
|
|
|
646
837
|
|
|
647
838
|
#### String Editors Input Attributes
|
|
648
839
|
|
|
649
|
-
You can set custom attributes such as **placeholder**, **class** and **data-** on the input field
|
|
840
|
+
You can set custom attributes such as **placeholder**, **class** and **data-** on the input field and on the editor container
|
|
841
|
+
using the special options keyword `inputAttributes` and `containerAttributes`.
|
|
650
842
|
|
|
651
843
|
Like this:
|
|
652
844
|
|
|
@@ -660,6 +852,10 @@ Like this:
|
|
|
660
852
|
"inputAttributes": {
|
|
661
853
|
"placeholder": "your name here...",
|
|
662
854
|
"class": "myclass"
|
|
855
|
+
},
|
|
856
|
+
"containerAttributes": {
|
|
857
|
+
"data-container": "my-container",
|
|
858
|
+
"class": "my-container-class"
|
|
663
859
|
}
|
|
664
860
|
}
|
|
665
861
|
}
|
|
@@ -671,23 +867,18 @@ Like this:
|
|
|
671
867
|
|
|
672
868
|
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.
|
|
673
869
|
|
|
674
|
-
__SCEditor__ provides WYSIWYG editing of HTML and BBCode. To use it, set the format to `
|
|
870
|
+
__SCEditor__ provides WYSIWYG editing of HTML and BBCode. To use it, set the format to `xhtml` or `bbcode` and set the `wysiwyg` option to `true`:
|
|
675
871
|
|
|
676
872
|
```json
|
|
677
873
|
{
|
|
678
874
|
"type": "string",
|
|
679
|
-
"format": "
|
|
875
|
+
"format": "xhtml",
|
|
680
876
|
"options": {
|
|
681
877
|
"wysiwyg": true
|
|
682
878
|
}
|
|
683
879
|
}
|
|
684
880
|
```
|
|
685
881
|
|
|
686
|
-
You can configure SCEditor by setting configuration options in `JSONEditor.plugins.sceditor`. Here's an example:
|
|
687
|
-
|
|
688
|
-
```js
|
|
689
|
-
JSONEditor.plugins.sceditor.emoticonsEnabled = false;
|
|
690
|
-
```
|
|
691
882
|
|
|
692
883
|
__SimpleMDE__ is a simple Markdown editor with live preview. To use it, set the format to `markdown`:
|
|
693
884
|
|
|
@@ -698,6 +889,33 @@ __SimpleMDE__ is a simple Markdown editor with live preview. To use it, set the
|
|
|
698
889
|
}
|
|
699
890
|
```
|
|
700
891
|
|
|
892
|
+
To customize the editor, add the [configuration](https://github.com/sparksuite/simplemde-markdown-editor#configuration) in the `simplemde` option:
|
|
893
|
+
|
|
894
|
+
```json
|
|
895
|
+
{
|
|
896
|
+
"type": "string",
|
|
897
|
+
"format": "markdown",
|
|
898
|
+
"options": {
|
|
899
|
+
"simplemde": {
|
|
900
|
+
"toolbar": [
|
|
901
|
+
"bold",
|
|
902
|
+
"italic",
|
|
903
|
+
"heading",
|
|
904
|
+
"|",
|
|
905
|
+
"link",
|
|
906
|
+
"quote",
|
|
907
|
+
"|",
|
|
908
|
+
"preview",
|
|
909
|
+
"fullscreen",
|
|
910
|
+
"guide"
|
|
911
|
+
],
|
|
912
|
+
"spellChecker": false
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
```
|
|
917
|
+
|
|
918
|
+
|
|
701
919
|
__Ace Editor__ is a syntax highlighting source code editor. You can use it by setting the format to any of the following:
|
|
702
920
|
|
|
703
921
|
* actionscript
|
|
@@ -736,8 +954,10 @@ __Ace Editor__ is a syntax highlighting source code editor. You can use it by se
|
|
|
736
954
|
* pgsql
|
|
737
955
|
* php
|
|
738
956
|
* python
|
|
957
|
+
* prql
|
|
739
958
|
* r
|
|
740
959
|
* ruby
|
|
960
|
+
* rust
|
|
741
961
|
* sass
|
|
742
962
|
* scala
|
|
743
963
|
* scss
|
|
@@ -745,10 +965,12 @@ __Ace Editor__ is a syntax highlighting source code editor. You can use it by se
|
|
|
745
965
|
* sql
|
|
746
966
|
* stylus
|
|
747
967
|
* svg
|
|
968
|
+
* typescript
|
|
748
969
|
* twig
|
|
749
970
|
* vbscript
|
|
750
971
|
* xml
|
|
751
972
|
* yaml
|
|
973
|
+
* zig
|
|
752
974
|
|
|
753
975
|
```json
|
|
754
976
|
{
|
|
@@ -768,11 +990,6 @@ You can use the hyper-schema keyword `media` instead of `format` too if you pref
|
|
|
768
990
|
}
|
|
769
991
|
```
|
|
770
992
|
|
|
771
|
-
You can override the default Ace theme by setting the `JSONEditor.plugins.ace.theme` variable.
|
|
772
|
-
|
|
773
|
-
```js
|
|
774
|
-
JSONEditor.plugins.ace.theme = 'twilight';
|
|
775
|
-
```
|
|
776
993
|
|
|
777
994
|
You can enable [Ace editor options](https://github.com/ajaxorg/ace/wiki/Configuring-Ace) individually by setting the `options.ace` in schema.
|
|
778
995
|
|
|
@@ -791,6 +1008,57 @@ You can enable [Ace editor options](https://github.com/ajaxorg/ace/wiki/Configur
|
|
|
791
1008
|
}
|
|
792
1009
|
```
|
|
793
1010
|
|
|
1011
|
+
### Special editors
|
|
1012
|
+
|
|
1013
|
+
JSONEditor features specialized types of editors.
|
|
1014
|
+
|
|
1015
|
+
#### Button editor
|
|
1016
|
+
|
|
1017
|
+
Creates a button whose click callback can be defined in `JSONEditor.defaults.callbacks`. Options:
|
|
1018
|
+
|
|
1019
|
+
- `icon`: Renders an icon into the button. Must be supported by the iconLib used.
|
|
1020
|
+
- `validated`: With `true` the button is disabled until the whole editor is valid.
|
|
1021
|
+
- `action`: the name of the callback that will be invoked when the button is clicked.
|
|
1022
|
+
|
|
1023
|
+
> **Warning**
|
|
1024
|
+
> For the form to render properly all callbacks used in `action`s must also be defined in `JSONEditor.defaults.callbacks`.
|
|
1025
|
+
|
|
1026
|
+
```js
|
|
1027
|
+
JSONEditor.defaults.callbacks = {
|
|
1028
|
+
"button" : {
|
|
1029
|
+
"myAction" : function (jseditor, e) {
|
|
1030
|
+
alert('Button action')
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
```
|
|
1035
|
+
|
|
1036
|
+
```json
|
|
1037
|
+
{
|
|
1038
|
+
"format": "button",
|
|
1039
|
+
"options": {
|
|
1040
|
+
"button": {
|
|
1041
|
+
"text": "Search",
|
|
1042
|
+
"icon": "search",
|
|
1043
|
+
"action": "myAction",
|
|
1044
|
+
"validated": true
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
```
|
|
1049
|
+
|
|
1050
|
+
#### Info editor
|
|
1051
|
+
|
|
1052
|
+
Displays a label and a description text.
|
|
1053
|
+
|
|
1054
|
+
```json
|
|
1055
|
+
{
|
|
1056
|
+
"format": "info",
|
|
1057
|
+
"title": "Important:",
|
|
1058
|
+
"description": "Lorem ipsum dolor"
|
|
1059
|
+
}
|
|
1060
|
+
```
|
|
1061
|
+
|
|
794
1062
|
#### Booleans
|
|
795
1063
|
|
|
796
1064
|
The default boolean editor is a select box with options "true" and "false". To use a checkbox instead, set the format to `checkbox`.
|
|
@@ -858,6 +1126,49 @@ You can override this default by passing in a format:
|
|
|
858
1126
|
}
|
|
859
1127
|
```
|
|
860
1128
|
|
|
1129
|
+
#### Array events
|
|
1130
|
+
|
|
1131
|
+
When an array item is added, removed, moved up, moved or removed the json editor will trigger a relative event.
|
|
1132
|
+
|
|
1133
|
+
```javascript
|
|
1134
|
+
editor.on('moveRow', editor => {
|
|
1135
|
+
console.log('moveRow', editor)
|
|
1136
|
+
});
|
|
1137
|
+
|
|
1138
|
+
editor.on('addRow', editor => {
|
|
1139
|
+
console.log('addRow', editor)
|
|
1140
|
+
});
|
|
1141
|
+
|
|
1142
|
+
editor.on('deleteRow', deletedValue => {
|
|
1143
|
+
console.log('deleteRow', deletedValue)
|
|
1144
|
+
});
|
|
1145
|
+
|
|
1146
|
+
editor.on('deleteAllRows', deletedValues => {
|
|
1147
|
+
console.log('deleteAllRows', deletedValues)
|
|
1148
|
+
});
|
|
1149
|
+
```
|
|
1150
|
+
|
|
1151
|
+
Drag and drop for array item is supported to perform a quick item moving.
|
|
1152
|
+
For array editor with format=`tabs` or `tabs-top`, you can drag the tab header directly.
|
|
1153
|
+
For the default array editor (or format=`table`), you have to drag the array item panel with Ctrl key pressed (to avoid side-effect of draggable panel), or drag any text in the input box to another item panel.
|
|
1154
|
+
|
|
1155
|
+
#### Schema loader events
|
|
1156
|
+
|
|
1157
|
+
When schemas are loaded via a request, the `schemaLoaded` event is triggered individually for each schema after its loading.
|
|
1158
|
+
Once the loading of all schemas is completed, the `allSchemasLoaded` event is triggered.
|
|
1159
|
+
|
|
1160
|
+
```javascript
|
|
1161
|
+
editor.on('schemaLoaded', (payload) => {
|
|
1162
|
+
console.log('schemasLoaded', payload.schemaUrl)
|
|
1163
|
+
console.log('schemasLoaded', payload.schema)
|
|
1164
|
+
})
|
|
1165
|
+
|
|
1166
|
+
editor.on('allSchemasLoaded', () => {
|
|
1167
|
+
console.log('allSchemasLoaded')
|
|
1168
|
+
})
|
|
1169
|
+
```
|
|
1170
|
+
|
|
1171
|
+
|
|
861
1172
|
#### Objects
|
|
862
1173
|
|
|
863
1174
|
The default object layout is one child editor per row. The `grid` format will instead put multiple child editors per row.
|
|
@@ -916,7 +1227,7 @@ It introduces the new `grid-break` property to breaks the current row leaving a
|
|
|
916
1227
|
```
|
|
917
1228
|
|
|
918
1229
|
|
|
919
|
-
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.
|
|
1230
|
+
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.
|
|
920
1231
|
Panel tabs titles came from object or array titles and for the grouping panel it defaults to "Basic", unless `basicCategoryTitle` is defined.
|
|
921
1232
|
|
|
922
1233
|
```json
|
|
@@ -939,23 +1250,29 @@ Editor Options
|
|
|
939
1250
|
|
|
940
1251
|
Editors can accept options which alter the behavior in some way.
|
|
941
1252
|
|
|
942
|
-
*
|
|
943
|
-
*
|
|
944
|
-
*
|
|
945
|
-
*
|
|
946
|
-
*
|
|
947
|
-
*
|
|
948
|
-
*
|
|
949
|
-
*
|
|
950
|
-
*
|
|
951
|
-
*
|
|
952
|
-
*
|
|
953
|
-
*
|
|
954
|
-
*
|
|
955
|
-
*
|
|
956
|
-
*
|
|
957
|
-
*
|
|
958
|
-
*
|
|
1253
|
+
* `switcher` - If set to false and using oneOf or anyOf, a multiple editor is not created, but validation still applies. Should be used with schemas with same type.
|
|
1254
|
+
* `titleHidden` - If set to true, the editor title will be visually hidden
|
|
1255
|
+
* `collapsed` - If set to true, the editor will start collapsed (works for objects and arrays)
|
|
1256
|
+
* `disable_array_add` - If set to true, the "add row" button will be hidden (works for arrays)
|
|
1257
|
+
* `disable_array_delete` - If set to true, all of the "delete" buttons will be hidden (works for arrays)
|
|
1258
|
+
* `disable_array_delete_all_rows` - If set to true, just the "delete all rows" button will be hidden (works for arrays)
|
|
1259
|
+
* `disable_array_delete_last_row` - If set to true, just the "delete last row" buttons will be hidden (works for arrays)
|
|
1260
|
+
* `disable_array_reorder` - If set to true, the "move up/down" buttons will be hidden (works for arrays)
|
|
1261
|
+
* `disable_collapse` - If set to true, the collapse button will be hidden (works for objects and arrays)
|
|
1262
|
+
* `disable_edit_json` - If set to true, the Edit JSON button will be hidden (works for objects)
|
|
1263
|
+
* `disable_properties` - If set to true, the Edit Properties button will be hidden (works for objects)
|
|
1264
|
+
* `array_controls_top` - If set to true, array controls (add, delete etc) will be displayed at top of list (works for arrays)
|
|
1265
|
+
* `enum` - See [Enum options](#enum-options)
|
|
1266
|
+
* `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.
|
|
1267
|
+
* `expand_height` - If set to true, the input will auto expand/contract to fit the content. Works best with textareas.
|
|
1268
|
+
* `grid_columns` - Explicitly set the number of grid columns (1-12) for the editor if it's within an object using a grid layout.
|
|
1269
|
+
* `hidden` - If set to true, the editor will not appear in the UI (works for all types)
|
|
1270
|
+
* `input_height` - Explicitly set the height of the input element. Should be a valid CSS width string (e.g. "100px"). Works best with textareas.
|
|
1271
|
+
* `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.
|
|
1272
|
+
* `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().
|
|
1273
|
+
* `remove_false_properties` - If set to `true` for an object, object properties with value `false` will not be returned by getValue().
|
|
1274
|
+
* `has_placeholder_option` - If set to true, a placeholder option will be added to the select editor input.
|
|
1275
|
+
* `placeholder_option_text` - Text displayed in select placeholder option.
|
|
959
1276
|
|
|
960
1277
|
```json
|
|
961
1278
|
{
|
|
@@ -990,6 +1307,43 @@ Using the option `infoText`, will create a info button, displaying the text you
|
|
|
990
1307
|
}
|
|
991
1308
|
```
|
|
992
1309
|
|
|
1310
|
+
Enum options
|
|
1311
|
+
------------------
|
|
1312
|
+
|
|
1313
|
+
Using the option `enum`, it is possible to modify how enums with format `checkbox` (default) are displayed in the editor.
|
|
1314
|
+
It is an array of objects (described below), which must be in the same order as defined with the `enum` keyword.
|
|
1315
|
+
|
|
1316
|
+
Currently, the following is supported:
|
|
1317
|
+
|
|
1318
|
+
* `title`: *Optional* Display value shown instead of the enum value
|
|
1319
|
+
* `infoText`: *Optional* Creates an info button next to the title, displaying the text you set, on hovering.
|
|
1320
|
+
|
|
1321
|
+
It is possible also to set these options only for some enum values, to skip one enum value, define an empty object (`{}`).
|
|
1322
|
+
|
|
1323
|
+
```json
|
|
1324
|
+
{
|
|
1325
|
+
"type": "array",
|
|
1326
|
+
"items": {
|
|
1327
|
+
"type": "string",
|
|
1328
|
+
"enum": ["1", "2", "3", "4"],
|
|
1329
|
+
"options": {
|
|
1330
|
+
"enum": [
|
|
1331
|
+
{},
|
|
1332
|
+
{
|
|
1333
|
+
"title": "Title 2"
|
|
1334
|
+
},
|
|
1335
|
+
{ "infoText": "InfoText 3" },
|
|
1336
|
+
{
|
|
1337
|
+
"title": "Title 4",
|
|
1338
|
+
"infoText": "InfoText 4"
|
|
1339
|
+
}
|
|
1340
|
+
]
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
```
|
|
1345
|
+
|
|
1346
|
+
If both options `enum_titles[x]` and `enum[x].title` are set for the enum value `x`, than the title set under `enum[x].title` will be used.
|
|
993
1347
|
|
|
994
1348
|
Dependencies
|
|
995
1349
|
------------------
|
|
@@ -1034,6 +1388,51 @@ Here's an example schema:
|
|
|
1034
1388
|
}
|
|
1035
1389
|
```
|
|
1036
1390
|
|
|
1391
|
+
Keys can also be an absolute path like `root.property.nested_property`
|
|
1392
|
+
|
|
1393
|
+
```json
|
|
1394
|
+
{
|
|
1395
|
+
"title": "Person",
|
|
1396
|
+
"type": "object",
|
|
1397
|
+
"required": [
|
|
1398
|
+
"gender"
|
|
1399
|
+
],
|
|
1400
|
+
"properties": {
|
|
1401
|
+
"gender": {
|
|
1402
|
+
"title": "Gender",
|
|
1403
|
+
"type": "string",
|
|
1404
|
+
"enum": [
|
|
1405
|
+
"female",
|
|
1406
|
+
"male"
|
|
1407
|
+
]
|
|
1408
|
+
},
|
|
1409
|
+
"age": {
|
|
1410
|
+
"type": "object",
|
|
1411
|
+
"properties": {
|
|
1412
|
+
"maleSpecificAge": {
|
|
1413
|
+
"type": "string",
|
|
1414
|
+
"title": "Male specific age question?",
|
|
1415
|
+
"options": {
|
|
1416
|
+
"dependencies": {
|
|
1417
|
+
"root.gender": "male"
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
},
|
|
1421
|
+
"femaleSpecificAge": {
|
|
1422
|
+
"type": "string",
|
|
1423
|
+
"title": "Female specific age question?",
|
|
1424
|
+
"options": {
|
|
1425
|
+
"dependencies": {
|
|
1426
|
+
"root.gender": "female"
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
```
|
|
1435
|
+
|
|
1037
1436
|
The `dependencies` keyword from the JSON Schema specification is not nearly flexible enough to handle most use cases,
|
|
1038
1437
|
so JSON Editor introduces a couple custom keywords that help in this regard.
|
|
1039
1438
|
|
|
@@ -1117,7 +1516,7 @@ JSONEditor.defaults.options.template = 'handlebars';
|
|
|
1117
1516
|
You can set the template engine on a per-instance basis as well:
|
|
1118
1517
|
|
|
1119
1518
|
```js
|
|
1120
|
-
|
|
1519
|
+
const editor = new JSONEditor(element,{
|
|
1121
1520
|
schema: schema,
|
|
1122
1521
|
template: 'hogan'
|
|
1123
1522
|
});
|
|
@@ -1147,6 +1546,40 @@ Here is the completed `full_name` example using the default barebones template e
|
|
|
1147
1546
|
}
|
|
1148
1547
|
```
|
|
1149
1548
|
|
|
1549
|
+
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.
|
|
1550
|
+
|
|
1551
|
+
|
|
1552
|
+
Example Schema:
|
|
1553
|
+
```js+jinja
|
|
1554
|
+
{
|
|
1555
|
+
"type": "object",
|
|
1556
|
+
"properties": {
|
|
1557
|
+
"first_name": {
|
|
1558
|
+
"type": "string"
|
|
1559
|
+
},
|
|
1560
|
+
"last_name": {
|
|
1561
|
+
"type": "string"
|
|
1562
|
+
},
|
|
1563
|
+
"full_name": {
|
|
1564
|
+
"type": "string",
|
|
1565
|
+
"template": "callbackFunction",
|
|
1566
|
+
"watch": {
|
|
1567
|
+
"fname": "first_name",
|
|
1568
|
+
"lname": "last_name"
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
```
|
|
1574
|
+
Example Callback function:
|
|
1575
|
+
```js+jinja
|
|
1576
|
+
window.JSONEditor.defaults.callbacks.template = {
|
|
1577
|
+
"callbackFunction": (jseditor,e) => {
|
|
1578
|
+
return e.fname + " " + e.lname;
|
|
1579
|
+
}
|
|
1580
|
+
};
|
|
1581
|
+
```
|
|
1582
|
+
|
|
1150
1583
|
### Enum Values
|
|
1151
1584
|
|
|
1152
1585
|
Another common dependency is a drop down menu whose possible values depend on other fields. Here's an example:
|
|
@@ -1282,14 +1715,67 @@ also make it work with an array of objects. Here's an example:
|
|
|
1282
1715
|
|
|
1283
1716
|
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.
|
|
1284
1717
|
|
|
1718
|
+
#### JavaScript callbacks
|
|
1719
|
+
It is also possible to use JavaScript callback functions instead of templates for the enumSource properties properties: `value`, `title` and `filter`.
|
|
1720
|
+
|
|
1721
|
+
**Example Schema:**
|
|
1722
|
+
````json
|
|
1723
|
+
{
|
|
1724
|
+
"type": "object",
|
|
1725
|
+
"properties": {
|
|
1726
|
+
"possible_colors": {
|
|
1727
|
+
"type": "array",
|
|
1728
|
+
"format": "table",
|
|
1729
|
+
"items": {
|
|
1730
|
+
"type": "object",
|
|
1731
|
+
"properties": {
|
|
1732
|
+
"text": {
|
|
1733
|
+
"type": "string"
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
},
|
|
1738
|
+
"primary_color": {
|
|
1739
|
+
"type": "string",
|
|
1740
|
+
"watch": {
|
|
1741
|
+
"colors": "possible_colors"
|
|
1742
|
+
},
|
|
1743
|
+
"enumSource": [{
|
|
1744
|
+
"source": "colors",
|
|
1745
|
+
"filter": "enumFilterCB",
|
|
1746
|
+
"title": "enumTitleCB",
|
|
1747
|
+
"value": "enumValueCB"
|
|
1748
|
+
}]
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
````
|
|
1753
|
+
|
|
1754
|
+
**Example JavaScript callbacks:**
|
|
1755
|
+
````javascript
|
|
1756
|
+
window.JSONEditor.defaults.callbacks.template = {
|
|
1757
|
+
"enumFilterCB": (jseditor, e) => {
|
|
1758
|
+
if (e.item.text.toLowerCase() == 'red') return ""; // "red" is not allowed
|
|
1759
|
+
return e.item.text;
|
|
1760
|
+
},
|
|
1761
|
+
"enumTitleCB": (jseditor, e) => e.item.text.toUpperCase(),
|
|
1762
|
+
"enumValueCB": (jseditor, e) => e.item.text.toLowerCase()
|
|
1763
|
+
};
|
|
1764
|
+
````
|
|
1765
|
+
|
|
1766
|
+
#### Sorting
|
|
1767
|
+
|
|
1768
|
+
To sort the dynamic EnumSource, you can set the EnumSource property `sort` to either `asc` or `desc`.
|
|
1769
|
+
|
|
1770
|
+
|
|
1285
1771
|
### Dynamic Headers
|
|
1286
1772
|
|
|
1287
1773
|
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.
|
|
1288
1774
|
|
|
1289
|
-
Consider the example of an array of children. Without dynamic headers, the UI for the array elements would show `Child 1`, `Child 2`, etc..
|
|
1775
|
+
Consider the example of an array of children. Without dynamic headers, the UI for the array elements would show `Child 1`, `Child 2`, etc..
|
|
1290
1776
|
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)`.
|
|
1291
1777
|
|
|
1292
|
-
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}`).
|
|
1778
|
+
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`, extra child variable `properties.${PROPERTY_NAME}.enumTitle` and the field's value `self` (e.g. `{"name": "John", "age": 9}`).
|
|
1293
1779
|
|
|
1294
1780
|
```js+jinja
|
|
1295
1781
|
{
|
|
@@ -1298,10 +1784,18 @@ To accomplish this, use the `headerTemplate` property. All of the watched varia
|
|
|
1298
1784
|
"items": {
|
|
1299
1785
|
"type": "object",
|
|
1300
1786
|
"title": "Child",
|
|
1301
|
-
"headerTemplate": "{{ i1 }} - {{ self.name }} (age {{ self.age }})",
|
|
1787
|
+
"headerTemplate": "{{ i1 }} - {{ self.name }} (age {{ self.age }}) has a {{ properties.pet.enumTitle }}",
|
|
1302
1788
|
"properties": {
|
|
1303
1789
|
"name": { "type": "string" },
|
|
1304
|
-
"age": { "type": "integer" }
|
|
1790
|
+
"age": { "type": "integer" },
|
|
1791
|
+
"pet": {
|
|
1792
|
+
"title": "Pet",
|
|
1793
|
+
"type": "string",
|
|
1794
|
+
"enum": [ "pet_1", "pet_2" ],
|
|
1795
|
+
"options": {
|
|
1796
|
+
"enum_titles": [ "Dog", "Cat" ]
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1305
1799
|
}
|
|
1306
1800
|
}
|
|
1307
1801
|
}
|
|
@@ -1313,22 +1807,21 @@ If one of the included template engines isn't sufficient,
|
|
|
1313
1807
|
you can use any custom template engine with a `compile` method. For example:
|
|
1314
1808
|
|
|
1315
1809
|
```js
|
|
1316
|
-
|
|
1317
|
-
compile:
|
|
1810
|
+
const myengine = {
|
|
1811
|
+
compile: template =>
|
|
1318
1812
|
// Compile should return a render function
|
|
1319
|
-
|
|
1813
|
+
vars => {
|
|
1320
1814
|
// A real template engine would render the template here
|
|
1321
|
-
|
|
1815
|
+
const result = template;
|
|
1322
1816
|
return result;
|
|
1323
1817
|
}
|
|
1324
|
-
}
|
|
1325
1818
|
};
|
|
1326
1819
|
|
|
1327
1820
|
// Set globally
|
|
1328
1821
|
JSONEditor.defaults.options.template = myengine;
|
|
1329
1822
|
|
|
1330
1823
|
// Set on a per-instance basis
|
|
1331
|
-
|
|
1824
|
+
const editor = new JSONEditor(element,{
|
|
1332
1825
|
schema: schema,
|
|
1333
1826
|
template: myengine
|
|
1334
1827
|
});
|
|
@@ -1360,7 +1853,29 @@ By default, all instances of JSON Editor will use the `en` language. To overrid
|
|
|
1360
1853
|
JSONEditor.defaults.language = "es";
|
|
1361
1854
|
```
|
|
1362
1855
|
|
|
1363
|
-
|
|
1856
|
+
You can also override translations per editor in the it's schema options.
|
|
1857
|
+
|
|
1858
|
+
````json
|
|
1859
|
+
"error_const": {
|
|
1860
|
+
"type": "string",
|
|
1861
|
+
"title": "error_const",
|
|
1862
|
+
"const": "test",
|
|
1863
|
+
"default": "something else",
|
|
1864
|
+
"options": {
|
|
1865
|
+
"error_messages": {
|
|
1866
|
+
"en": {
|
|
1867
|
+
"error_const": "CUSTOM EN: Value must be the constant value"
|
|
1868
|
+
},
|
|
1869
|
+
"es": {
|
|
1870
|
+
"error_const": "CUSTOM ES: Value must be the constant value"
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
````
|
|
1876
|
+
|
|
1877
|
+
|
|
1878
|
+
Button Customization
|
|
1364
1879
|
-----------------
|
|
1365
1880
|
|
|
1366
1881
|
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.
|
|
@@ -1395,7 +1910,7 @@ Let's say you make a custom `location` editor for editing geo data. You can add
|
|
|
1395
1910
|
```js
|
|
1396
1911
|
// Add a resolver function to the beginning of the resolver list
|
|
1397
1912
|
// This will make it run before any other ones
|
|
1398
|
-
JSONEditor.defaults.resolvers.unshift(
|
|
1913
|
+
JSONEditor.defaults.resolvers.unshift(schema => {
|
|
1399
1914
|
if(schema.type === "object" && schema.format === "location") {
|
|
1400
1915
|
return "location";
|
|
1401
1916
|
}
|
|
@@ -1434,16 +1949,6 @@ The possibilities are endless. Some ideas:
|
|
|
1434
1949
|
* Better editor for arrays of strings (tag editor)
|
|
1435
1950
|
* Canvas based image editor that produces Base64 data URLs
|
|
1436
1951
|
|
|
1437
|
-
Select2 & Selectize Support
|
|
1438
|
-
----------------
|
|
1439
|
-
Select2 support is enabled by default and will become active if the Select2 library is detected.
|
|
1440
|
-
|
|
1441
|
-
Selectize support is enabled via the following snippet:
|
|
1442
|
-
```js
|
|
1443
|
-
JSONEditor.plugins.selectize.enable = true;
|
|
1444
|
-
```
|
|
1445
|
-
See the demo for an example of the `array` and `select` editor with Selectize support enabled.
|
|
1446
|
-
|
|
1447
1952
|
Custom Validation
|
|
1448
1953
|
----------------
|
|
1449
1954
|
|
|
@@ -1453,10 +1958,10 @@ Let's say you want to force all schemas with `format` set to `date` to match the
|
|
|
1453
1958
|
|
|
1454
1959
|
```js
|
|
1455
1960
|
// Custom validators must return an array of errors or an empty array if valid
|
|
1456
|
-
JSONEditor.defaults.custom_validators.push(
|
|
1457
|
-
|
|
1458
|
-
if(schema.format==="date") {
|
|
1459
|
-
if(!/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test(value)) {
|
|
1961
|
+
JSONEditor.defaults.custom_validators.push((schema, value, path) => {
|
|
1962
|
+
const errors = [];
|
|
1963
|
+
if (schema.format==="date") {
|
|
1964
|
+
if (!/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test(value)) {
|
|
1460
1965
|
// Errors must be an object with `path`, `property`, and `message`
|
|
1461
1966
|
errors.push({
|
|
1462
1967
|
path: path,
|
|
@@ -1469,26 +1974,32 @@ JSONEditor.defaults.custom_validators.push(function(schema, value, path) {
|
|
|
1469
1974
|
});
|
|
1470
1975
|
```
|
|
1471
1976
|
|
|
1472
|
-
|
|
1473
|
-
|
|
1977
|
+
Override Editors Methods
|
|
1978
|
+
----------------
|
|
1474
1979
|
|
|
1475
|
-
|
|
1980
|
+
```js
|
|
1981
|
+
// override class method
|
|
1982
|
+
JSONEditor.defaults.editors.integer.prototype.sanitize = function(value) {
|
|
1983
|
+
return value
|
|
1984
|
+
};
|
|
1985
|
+
```
|
|
1476
1986
|
|
|
1477
|
-
|
|
1987
|
+
or
|
|
1478
1988
|
|
|
1479
1989
|
```js
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1990
|
+
// override object method
|
|
1991
|
+
var path ="root.integerfield";
|
|
1992
|
+
editor.getEditor(path).sanitize = function(value) {
|
|
1993
|
+
return value
|
|
1994
|
+
};
|
|
1995
|
+
```
|
|
1996
|
+
|
|
1997
|
+
Support Legacy Browser (not tested)
|
|
1998
|
+
----------------------
|
|
1999
|
+
|
|
2000
|
+
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.
|
|
2001
|
+
|
|
2002
|
+
```
|
|
2003
|
+
<script src="https://unpkg.com/core-js-bundle@latest/minified.js"></script>
|
|
2004
|
+
<script src="https://cdn.jsdelivr.net/npm/@json-editor/json-editor@latest/dist/jsoneditor.min.js"></script>
|
|
1494
2005
|
```
|