From 620c5e0b898d7e74ed022b7941e3e8d86e8d8a54 Mon Sep 17 00:00:00 2001 From: jos Date: Wed, 15 Aug 2018 11:02:54 +0200 Subject: [PATCH] Add className `jsoneditor-validation-error` to nodes with a validation error --- HISTORY.md | 2 ++ src/js/Node.js | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 4e62aab..39e9d7c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -6,6 +6,8 @@ https://github.com/josdejong/jsoneditor ## not yet released, version 5.23.0 - Implemented support for custom validation using a new `onValidate` callback. +- In tree mode, nodes containing a validation error now have a className + `jsoneditor-validation-error` which can be used for custom styling. ## 2018-08-13, version 5.22.0 diff --git a/src/js/Node.js b/src/js/Node.js index 494ff63..d2e5206 100644 --- a/src/js/Node.js +++ b/src/js/Node.js @@ -251,7 +251,7 @@ Node.prototype.setError = function (error, child) { this.errorChild = child; if (this.dom && this.dom.tr) { - this.updateError() + this.updateError(); } }; @@ -262,6 +262,8 @@ Node.prototype.updateError = function() { var error = this.error; var tdError = this.dom.tdError; if (error && this.dom && this.dom.tr) { + util.addClassName(this.dom.tr, 'jsoneditor-validation-error'); + if (!tdError) { tdError = document.createElement('td'); this.dom.tdError = tdError; @@ -317,6 +319,8 @@ Node.prototype.updateError = function() { tdError.appendChild(button); } else { + util.removeClassName(this.dom.tr, 'jsoneditor-validation-error'); + if (tdError) { this.dom.tdError.parentNode.removeChild(this.dom.tdError); delete this.dom.tdError;