From 088e3e537422d5097c6475f6ae772cf30b640165 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Tue, 26 Apr 2016 22:00:02 +0100 Subject: [PATCH] Validate all edit dialog inputs when one changes --- editor/js/ui/editor.js | 45 +++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/editor/js/ui/editor.js b/editor/js/ui/editor.js index 908b3aca0..677f0d649 100644 --- a/editor/js/ui/editor.js +++ b/editor/js/ui/editor.js @@ -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) { @@ -735,7 +748,7 @@ RED.editor = (function() { trayHeader.append(''); RED.keyboard.disable(); - + var dialogForm = $('
').appendTo(trayBody); dialogForm.html($("script[data-template-name='"+type+"']").html()); dialogForm.find('[data-i18n]').each(function() {