From 58f460a383b6e30501b5f28e2eeb0d9beb0b79d9 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Wed, 23 Sep 2020 15:44:04 +0200 Subject: [PATCH] Log a clear error in the console when the returned value of `onEditable` is invalid. See #1112 --- HISTORY.md | 6 ++++++ src/js/Node.js | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 56a06e4..6feacb9 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,6 +3,12 @@ https://github.com/josdejong/jsoneditor +## not yet published, version 9.1.2 + +- Log a clear error in the console when the returned value of `onEditable` is + invalid. See #1112. + + ## 2020-09-23, version 9.1.1 - Fix #1111: Enum dropdown not showing when using patternProperties for schema. diff --git a/src/js/Node.js b/src/js/Node.js index c12ecf7..fe396c2 100644 --- a/src/js/Node.js +++ b/src/js/Node.js @@ -104,9 +104,16 @@ export class Node { if (typeof editable === 'boolean') { this.editable.field = editable this.editable.value = editable - } else { + } else if (typeof editable === 'object' && editable !== null) { if (typeof editable.field === 'boolean') this.editable.field = editable.field if (typeof editable.value === 'boolean') this.editable.value = editable.value + } else { + console.error( 'Invalid return value for function onEditable. ' + + 'Actual value:', editable, '.', + 'Either a boolean or object { field: boolean, value: boolean } expected.') + + this.editable.field = false + this.editable.value = false } } }