Fix non-boolean returned value + try to find validation msg in tooltip

This commit is contained in:
GogoVega 2023-12-17 19:22:44 +01:00
parent ba08cf0417
commit 282d52cf0b
No known key found for this signature in database
GPG Key ID: E1E048B63AC5AC2B
4 changed files with 17 additions and 4 deletions

View File

@ -53,6 +53,7 @@
* Returns the popover object with the following properties/functions: * Returns the popover object with the following properties/functions:
* properties: * properties:
* - element : DOM element - the popover dom element * - element : DOM element - the popover dom element
* - content : string|function - the popover content
* functions: * functions:
* - setContent(content) - change the popover content. This only works if the * - setContent(content) - change the popover content. This only works if the
* popover is not currently displayed. It does not * popover is not currently displayed. It does not
@ -159,7 +160,7 @@ RED.popover = (function() {
var size = options.size||"default"; var size = options.size||"default";
var popupOffset = options.offset || 0; var popupOffset = options.offset || 0;
if (!deltaSizes[size]) { if (!deltaSizes[size]) {
throw new Error("Invalid RED.popover size value:",size); throw new Error("Invalid RED.popover size value:" + size);
} }
var timer = null; var timer = null;
@ -419,6 +420,7 @@ RED.popover = (function() {
} }
var res = { var res = {
get element() { return div }, get element() { return div },
get content() { return content },
setContent: function(_content) { setContent: function(_content) {
content = _content; content = _content;
@ -440,7 +442,6 @@ RED.popover = (function() {
} }
} }
return res; return res;
} }
return { return {
@ -465,6 +466,9 @@ RED.popover = (function() {
content: label, content: label,
delay: { show: 750, hide: 50 } delay: { show: 750, hide: 50 }
}); });
popover.getContent = function () {
return content;
}
popover.setContent = function(newContent) { popover.setContent = function(newContent) {
content = newContent; content = newContent;
} }

View File

@ -1274,7 +1274,8 @@
tooltip.delete(); tooltip.delete();
} }
} }
return !!valid; // Must return a boolean
return (typeof valid === "string") ? false : valid;
}, },
show: function() { show: function() {
this.uiSelect.show(); this.uiSelect.show();

View File

@ -191,6 +191,14 @@ RED.editor = (function() {
const isTypedInput = input.length > 0 && input.next(".red-ui-typedInput-container").length > 0; const isTypedInput = input.length > 0 && input.next(".red-ui-typedInput-container").length > 0;
if (isTypedInput) { if (isTypedInput) {
valid = input.typedInput("validate"); 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;
}
}
} }
} }
} }

View File

@ -931,7 +931,7 @@ RED.utils = (function() {
} }
} else if (propertyType === 'msg' || propertyType === 'flow' || propertyType === 'global' ) { } else if (propertyType === 'msg' || propertyType === 'flow' || propertyType === 'global' ) {
// To avoid double label // To avoid double label
const valid = RED.utils.validatePropertyExpression(propertyValue, opt ? {} : undefined); const valid = RED.utils.validatePropertyExpression(propertyValue, opt ? {} : null);
if (valid !== true) { if (valid !== true) {
error = opt ? valid : RED._("validator.errors.invalid-prop"); error = opt ? valid : RED._("validator.errors.invalid-prop");
} }