1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Validate all edit dialog inputs when one changes

This commit is contained in:
Nick O'Leary 2016-04-26 22:00:02 +01:00
parent bac8a3092f
commit 088e3e5374

View File

@ -139,6 +139,32 @@ RED.editor = (function() {
return valid;
}
function validateNodeEditor(node,prefix) {
for (var prop in node._def.defaults) {
if (node._def.defaults.hasOwnProperty(prop)) {
validateNodeEditorProperty(node,node._def.defaults,prop,prefix);
}
}
if (node._def.credentials) {
for (prop in node._def.credentials) {
if (node._def.credentials.hasOwnProperty(prop)) {
validateNodeEditorProperty(node,node._def.credentials,prop,prefix);
}
}
}
}
function validateNodeEditorProperty(node,defaults,property,prefix) {
var input = $("#"+prefix+"-"+property);
if (input.length > 0) {
if (!validateNodeProperty(node, defaults, property,input.val())) {
input.addClass("input-error");
} else {
input.removeClass("input-error");
}
}
}
/**
* Called when the node's properties have changed.
* Marks the node as dirty and needing a size check.
@ -274,11 +300,7 @@ RED.editor = (function() {
*/
function attachPropertyChangeHandler(node,definition,property,prefix) {
$("#"+prefix+"-"+property).change(function() {
if (!validateNodeProperty(node, definition, property,this.value)) {
$(this).addClass("input-error");
} else {
$(this).removeClass("input-error");
}
validateNodeEditor(node,prefix);
});
}
@ -308,11 +330,6 @@ RED.editor = (function() {
attachPropertyChangeHandler(node, credDef, cred, prefix);
}
}
for (cred in credDef) {
if (credDef.hasOwnProperty(cred)) {
$("#" + prefix + "-" + cred).change();
}
}
}
/**
@ -380,11 +397,7 @@ RED.editor = (function() {
if (definition.oneditprepare) {
definition.oneditprepare.call(node);
}
for (var d in definition.defaults) {
if (definition.defaults.hasOwnProperty(d)) {
$("#"+prefix+"-"+d).change();
}
}
validateNodeEditor(node,prefix);
}
if (definition.credentials) {