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

TypedInput: handle user defined value/labels options

Fixes #1549
This commit is contained in:
Nick O'Leary 2018-01-14 00:24:36 +00:00
parent 298068b2b9
commit e762b7ff48
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -354,10 +354,27 @@
return this.element.val();
} else {
if (this.typeMap[this.propertyType].options) {
if (this.typeMap[this.propertyType].options.indexOf(value) === -1) {
value = "";
var validValue = false;
var label;
for (var i=0;i<this.typeMap[this.propertyType].options.length;i++) {
var op = this.typeMap[this.propertyType].options[i];
if (typeof op === "string") {
if (op === value) {
label = value;
validValue = true;
break;
}
this.optionSelectLabel.text(value);
} else if (op.value === value) {
label = op.label||op.value;
validValue = true;
break;
}
}
if (!validValue) {
value = "";
label = "";
}
this.optionSelectLabel.text(label);
}
this.element.val(value);
this.element.trigger('change',this.type(),value);
@ -394,11 +411,31 @@
that.value(v);
});
var currentVal = this.element.val();
if (opt.options.indexOf(currentVal) !== -1) {
var validValue = false;
var op;
for (var i=0;i<opt.options.length;i++) {
op = opt.options[i];
if (typeof op === "string") {
if (op === currentVal) {
this.optionSelectLabel.text(currentVal);
} else {
this.value(opt.options[0]);
validValue = true;
break;
}
} else if (op.value === currentVal) {
this.optionSelectLabel.text(op.label||op.value);
validValue = true;
break;
}
}
if (!validValue) {
op = opt.options[0];
if (typeof op === "string") {
this.value(op);
} else {
this.value(op.value);
}
}
console.log(validValue);
}
} else {
if (this.optionMenu) {