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

Add property validation to nodes using typedInput

This commit is contained in:
Nick O'Leary 2017-01-06 23:18:50 +00:00
parent 4b83d8160f
commit aafcfef387
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
5 changed files with 8 additions and 8 deletions

View File

@ -16,8 +16,8 @@
RED.validators = { RED.validators = {
number: function(){return function(v) { return v!=='' && !isNaN(v);}}, number: function(){return function(v) { return v!=='' && !isNaN(v);}},
regex: function(re){return function(v) { return re.test(v);}}, regex: function(re){return function(v) { return re.test(v);}},
typedInput: function(ptypeName) { return function(v) { typedInput: function(ptypeName,isConfig) { return function(v) {
var ptype = $("#node-input-"+ptypeName).val() || this[ptypeName]; var ptype = $("#node-"+(isConfig?"config-":"")+"input-"+ptypeName).val() || this[ptypeName];
if (ptype === 'json') { if (ptype === 'json') {
try { try {
JSON.parse(v); JSON.parse(v);
@ -25,7 +25,7 @@ RED.validators = {
} catch(err) { } catch(err) {
return false; return false;
} }
} else if (ptype === 'flow' || ptype === 'global' ) { } else if (ptype === 'msg' || ptype === 'flow' || ptype === 'global' ) {
return RED.utils.validatePropertyExpression(v); return RED.utils.validatePropertyExpression(v);
} else if (ptype === 'num') { } else if (ptype === 'num') {
return /^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/.test(v); return /^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/.test(v);

View File

@ -78,7 +78,7 @@
category: 'function', category: 'function',
defaults: { defaults: {
name: {value:""}, name: {value:""},
field: {value:"payload"}, field: {value:"payload", validate: RED.validators.typedInput("fieldType")},
fieldType: {value:"msg"}, fieldType: {value:"msg"},
format: {value:"handlebars"}, format: {value:"handlebars"},
syntax: {value:"mustache"}, syntax: {value:"mustache"},

View File

@ -85,8 +85,8 @@
category: 'function', category: 'function',
color:"#E6E0F8", color:"#E6E0F8",
defaults: { defaults: {
op1: {value:"1"}, op1: {value:"1", validate: RED.validators.typedInput("op1type")},
op2: {value:"0"}, op2: {value:"0", validate: RED.validators.typedInput("op2type")},
op1type: {value:"val"}, op1type: {value:"val"},
op2type: {value:"val"}, op2type: {value:"val"},
duration: {value:"250",required:true,validate:RED.validators.number()}, duration: {value:"250",required:true,validate:RED.validators.number()},

View File

@ -48,7 +48,7 @@
category: 'function', category: 'function',
defaults: { defaults: {
name: {value:""}, name: {value:""},
property: {value:"payload", required:true}, property: {value:"payload", required:true, validate: RED.validators.typedInput("propertyType")},
propertyType: { value:"msg" }, propertyType: { value:"msg" },
rules: {value:[{t:"eq", v:""}]}, rules: {value:[{t:"eq", v:""}]},
checkall: {value:"true", required:true}, checkall: {value:"true", required:true},

View File

@ -162,7 +162,7 @@
name: {value:""}, name: {value:""},
mode: {value:"auto"}, mode: {value:"auto"},
build: { value:"string"}, build: { value:"string"},
property: { value: "payload"}, property: { value: "payload", validate: RED.validators.typedInput("propertyType")},
propertyType: { value:"msg"}, propertyType: { value:"msg"},
key: {value:"topic"}, key: {value:"topic"},
joiner: { value:"\\n"}, joiner: { value:"\\n"},