From 282d52cf0b9717813a182462fa4599943d70b458 Mon Sep 17 00:00:00 2001 From: GogoVega <92022724+GogoVega@users.noreply.github.com> Date: Sun, 17 Dec 2023 19:22:44 +0100 Subject: [PATCH] Fix non-boolean returned value + try to find validation msg in tooltip --- .../@node-red/editor-client/src/js/ui/common/popover.js | 8 ++++++-- .../editor-client/src/js/ui/common/typedInput.js | 3 ++- .../@node-red/editor-client/src/js/ui/editor.js | 8 ++++++++ .../@node-red/editor-client/src/js/ui/utils.js | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/common/popover.js b/packages/node_modules/@node-red/editor-client/src/js/ui/common/popover.js index 9ddd3d866..1b0ded805 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/common/popover.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/common/popover.js @@ -53,6 +53,7 @@ * Returns the popover object with the following properties/functions: * properties: * - element : DOM element - the popover dom element + * - content : string|function - the popover content * functions: * - setContent(content) - change the popover content. This only works if the * popover is not currently displayed. It does not @@ -159,7 +160,7 @@ RED.popover = (function() { var size = options.size||"default"; var popupOffset = options.offset || 0; if (!deltaSizes[size]) { - throw new Error("Invalid RED.popover size value:",size); + throw new Error("Invalid RED.popover size value:" + size); } var timer = null; @@ -419,6 +420,7 @@ RED.popover = (function() { } var res = { get element() { return div }, + get content() { return content }, setContent: function(_content) { content = _content; @@ -440,7 +442,6 @@ RED.popover = (function() { } } return res; - } return { @@ -465,6 +466,9 @@ RED.popover = (function() { content: label, delay: { show: 750, hide: 50 } }); + popover.getContent = function () { + return content; + } popover.setContent = function(newContent) { content = newContent; } diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js b/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js index 752c24eff..f1ebfabe5 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js @@ -1274,7 +1274,8 @@ tooltip.delete(); } } - return !!valid; + // Must return a boolean + return (typeof valid === "string") ? false : valid; }, show: function() { this.uiSelect.show(); diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/editor.js b/packages/node_modules/@node-red/editor-client/src/js/ui/editor.js index 4908373c7..680aecd62 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/editor.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/editor.js @@ -191,6 +191,14 @@ RED.editor = (function() { const isTypedInput = input.length > 0 && input.next(".red-ui-typedInput-container").length > 0; if (isTypedInput) { valid = input.typedInput("validate"); + if (valid === false) { + // Try to find validation message in the tooltip + const tooltip = input.data("tooltip"); + if (tooltip) { + const content = tooltip.getContent(); + valid = label ? label + ": " + content : content; + } + } } } } diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/utils.js b/packages/node_modules/@node-red/editor-client/src/js/ui/utils.js index 1677dea04..b056ee1f1 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/utils.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/utils.js @@ -931,7 +931,7 @@ RED.utils = (function() { } } else if (propertyType === 'msg' || propertyType === 'flow' || propertyType === 'global' ) { // To avoid double label - const valid = RED.utils.validatePropertyExpression(propertyValue, opt ? {} : undefined); + const valid = RED.utils.validatePropertyExpression(propertyValue, opt ? {} : null); if (valid !== true) { error = opt ? valid : RED._("validator.errors.invalid-prop"); }