From 7c398aeef79789ab54d8d7468e87448b570819af Mon Sep 17 00:00:00 2001 From: jos Date: Sun, 17 Mar 2019 15:56:29 +0100 Subject: [PATCH] Update history. Fix JSON schema default value styling not working for `false` and `null`, and fixed the styling not updating when clicking a boolean checkbox (See #666) --- HISTORY.md | 4 +++- examples/07_json_schema_validation.html | 11 ++++++++--- src/js/Node.js | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 7e13e06..c82a457 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,8 +3,10 @@ https://github.com/josdejong/jsoneditor -## not yet published, version 5.31.2 +## not yet published, version 5.32.0 +- Implemented support for reckoning with JSON schema default values: custom + styling can be applied for default and non-default values. Thanks @AdamVig. - Fixed #667: resolving JSON Schema examples and descriptions did not always work for referenced schemas. Thanks @AdamVig. diff --git a/examples/07_json_schema_validation.html b/examples/07_json_schema_validation.html index 6969a2a..6c6dcaa 100644 --- a/examples/07_json_schema_validation.html +++ b/examples/07_json_schema_validation.html @@ -16,12 +16,16 @@ height: 500px; } + /* custom bold styling for non-default JSON schema values */ + .jsoneditor-is-not-default { + font-weight: bold; + }

JSON schema validation

- This example demonstrates JSON schema validation. The JSON object in this example must contain properties firstName and lastName, can can optionally have a property age which must be a positive integer. + This example demonstrates JSON schema validation. The JSON object in this example must contain properties like firstName and lastName, can can optionally have a property age which must be a positive integer.

See http://json-schema.org/ for more information. @@ -89,7 +93,8 @@ "examples": [ "Human Resources Coordinator", "Software Developer" - ] + ], + "default": "Software Developer" }, "address": { "type": "string" @@ -107,7 +112,7 @@ lastName: 'Doe', gender: null, age: "28", - availableToHire: 1, + availableToHire: true, job: { company: 'freelance', role: 'developer', diff --git a/src/js/Node.js b/src/js/Node.js index b03ac11..d3dfa41 100644 --- a/src/js/Node.js +++ b/src/js/Node.js @@ -1917,7 +1917,7 @@ Node.prototype._getDomField = function(silent) { */ Node.prototype._updateDomDefault = function () { // Short-circuit if schema is missing, has no default, or if Node has children - if (!this.schema || !this.schema.default || this._hasChilds()) { + if (!this.schema || this.schema.default === undefined || this._hasChilds()) { return; } @@ -2891,6 +2891,7 @@ Node.prototype.onEvent = function (event) { if (type == 'change' && target == dom.checkbox) { this.dom.value.innerHTML = !this.value; this._getDomValue(); + this._updateDomDefault(); } // update the value of the node based on the selected option