mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge 235858fe1a8a2d5f7d75465b033da7ecde03b55d into bb01f26f068b8e083e35fdf19dc9b36f8cf67068
This commit is contained in:
commit
5d6c65e922
@ -256,33 +256,58 @@ 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) {
|
function validateNodeEditorProperty(node, defaults, property, prefix) {
|
||||||
var input = $("#"+prefix+"-"+property);
|
let input = $("#"+prefix+"-"+property);
|
||||||
if (input.length > 0) {
|
if (input.length > 0) {
|
||||||
var value = input.val();
|
let value = input.val();
|
||||||
if (defaults[property].hasOwnProperty("format") && defaults[property].format !== "" && input[0].nodeName === "DIV") {
|
if (defaults[property].hasOwnProperty("format") && defaults[property].format !== "" && input[0].nodeName === "DIV") {
|
||||||
value = input.text();
|
value = input.text();
|
||||||
} else if (input.attr("type") === "checkbox") {
|
} else if (input.attr("type") === "checkbox") {
|
||||||
value = input.prop("checked");
|
value = input.prop("checked");
|
||||||
}
|
}
|
||||||
var valid = validateNodeProperty(node, defaults, property,value);
|
// 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) {
|
if (((typeof valid) === "string") || !valid) {
|
||||||
input.addClass("input-error");
|
input.addClass("input-error");
|
||||||
input.next(".red-ui-typedInput-container").addClass("input-error");
|
input.next(".red-ui-typedInput-container").addClass("input-error");
|
||||||
if ((typeof valid) === "string") {
|
if ((typeof valid) === "string") {
|
||||||
var tooltip = input.data("tooltip");
|
let tooltip = input.data("tooltip");
|
||||||
if (tooltip) {
|
if (tooltip) {
|
||||||
|
// If the input has a tooltip, just modify the content
|
||||||
tooltip.setContent(valid);
|
tooltip.setContent(valid);
|
||||||
}
|
} else {
|
||||||
else {
|
// If the input is typed => attach the tooltip to the wrap
|
||||||
tooltip = RED.popover.tooltip(input, valid);
|
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);
|
||||||
input.data("tooltip", tooltip);
|
input.data("tooltip", tooltip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
input.removeClass("input-error");
|
input.removeClass("input-error");
|
||||||
input.next(".red-ui-typedInput-container").removeClass("input-error");
|
input.next(".red-ui-typedInput-container").removeClass("input-error");
|
||||||
var tooltip = input.data("tooltip");
|
const tooltip = input.data("tooltip");
|
||||||
if (tooltip) {
|
if (tooltip) {
|
||||||
input.data("tooltip", null);
|
input.data("tooltip", null);
|
||||||
tooltip.delete();
|
tooltip.delete();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user