From b279ed3069b9b4650668595071bfe58e29b5e8c9 Mon Sep 17 00:00:00 2001 From: jos Date: Tue, 2 Apr 2019 21:09:17 +0200 Subject: [PATCH] Fix CSS class for default/non-default schema values not applied to enums, see (#666) --- HISTORY.md | 2 ++ src/js/Node.js | 25 +++++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 4624e25..ec4b33f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -8,6 +8,8 @@ https://github.com/josdejong/jsoneditor - Fixed #416: Clipped action menu for append nodes. - Improve detection of value type in transform modal. - Styling improvements in the transform modal. +- Fix CSS class for default/non-default schema values not applied to enums, + see (#666). ## 2018-03-28, version 5.32.1 diff --git a/src/js/Node.js b/src/js/Node.js index d3dfa41..e6100b3 100644 --- a/src/js/Node.js +++ b/src/js/Node.js @@ -1921,18 +1921,23 @@ Node.prototype._updateDomDefault = function () { return; } + // select either enum dropdown (select) or input value + const inputElement = this.dom.select + ? this.dom.select + : this.dom.value; + + if (!inputElement) { + return; + } + if (this.value === this.schema.default) { - if (this.dom.select) { - this.dom.value.removeAttribute('title'); - } else { - this.dom.value.title = translate('default'); - this.dom.value.classList.add('jsoneditor-is-default'); - this.dom.value.classList.remove('jsoneditor-is-not-default'); - } + inputElement.title = translate('default'); + util.addClassName(inputElement, 'jsoneditor-is-default'); + util.removeClassName(inputElement, 'jsoneditor-is-not-default'); } else { - this.dom.value.removeAttribute('title'); - this.dom.value.classList.remove('jsoneditor-is-default'); - this.dom.value.classList.add('jsoneditor-is-not-default'); + inputElement.removeAttribute('title'); + util.removeClassName(inputElement, 'jsoneditor-is-default'); + util.addClassName(inputElement, 'jsoneditor-is-not-default'); } };