Add some comments and ignore if no node validation for the property

This commit is contained in:
GogoVega 2024-06-02 17:22:01 +02:00
parent c6fedec66b
commit 235858fe1a
No known key found for this signature in database
GPG Key ID: E1E048B63AC5AC2B

View File

@ -242,6 +242,13 @@ RED.editor = (function() {
}
}
/**
* Called when an input in the edit box changes.
*
* Marks the input as error (red field) if the input's value is invalid.
* If the validation function returns a String, a tooltip will be attached to the input
* like that the user can see the error message.
*/
function validateNodeEditorProperty(node, defaults, property, prefix) {
let input = $("#"+prefix+"-"+property);
if (input.length > 0) {
@ -249,24 +256,32 @@ RED.editor = (function() {
if (defaults[property].hasOwnProperty("format") && defaults[property].format !== "" && input[0].nodeName === "DIV") {
value = input.text();
}
if (input.attr("type") === "hidden") { // Possible typeField
// Check if the input is a typeField
if (input.attr("type") === "hidden") {
const typedInput = input.closest("div").find("input[class='red-ui-typedInput']");
const typeField = typedInput.data("noderedTypedInput")?.typeField;
const isTypeField = input.is(typeField);
if (isTypeField) {
// If typeField, must retrieve the typedInput to add the `input-error` class
input = typedInput;
}
}
// If it's a typedInput and the node has no validator for this property, let's validate by typedInput
if (input.hasClass("red-ui-typedInput") && !defaults[property].validate) {
return;
}
const valid = validateNodeProperty(node, defaults, property, value);
// If the input is invalid
if (((typeof valid) === "string") || !valid) {
input.addClass("input-error");
input.next(".red-ui-typedInput-container").addClass("input-error");
if ((typeof valid) === "string") {
let tooltip = input.data("tooltip");
if (tooltip) {
// If the input has a tooltip, just modify the content
tooltip.setContent(valid);
} else {
// If the input is typed => need the wrap to attach the tooltip
// If the input is typed => attach the tooltip to the wrap
const typedInput = input.next(".red-ui-typedInput-container").find(".red-ui-typedInput-input-wrap");
const target = typedInput.length > 0 ? typedInput : input;
tooltip = RED.popover.tooltip(target, valid);