diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js b/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js index 0401be1b9..187dc066c 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js @@ -428,6 +428,10 @@ this.optionExpandButton = $('').appendTo(this.uiSelect); this.optionExpandButtonIcon = $('').appendTo(this.optionExpandButton); + + // Used to remember selections per-type to restore them when switching between types + this.oldValues = {}; + this.type(this.options.default||this.typeList[0].value); }catch(err) { console.log(err.stack); @@ -767,6 +771,24 @@ var that = this; var opt = this.typeMap[type]; if (opt && this.propertyType !== type) { + // If previousType is !null, then this is a change of the type, rather than the initialisation + var previousType = this.typeMap[this.propertyType]; + var typeChanged = !!previousType; + + if (typeChanged) { + if (previousType.options) { + this.oldValues[previousType.value] = this.input.val(); + } else if (previousType.hasValue === false) { + this.oldValues[previousType.value] = this.input.val(); + } else { + this.oldValues["_"] = this.input.val(); + } + if (opt.options || opt.hasValue === false) { + this.input.val(this.oldValues.hasOwnProperty(opt.value)?this.oldValues[opt.value]:(opt.default||[]).join(",")) + } else { + this.input.val(this.oldValues.hasOwnProperty("_")?this.oldValues["_"]:(opt.default||"")) + } + } this.propertyType = type; if (this.typeField) { this.typeField.val(type); @@ -865,8 +887,10 @@ // Check to see if value is a valid csv of // options. var currentValues = {}; + var selected = []; currentVal.split(",").forEach(function(v) { if (v) { + selected.push(v); currentValues[v] = true; } }); @@ -875,9 +899,11 @@ delete currentValues[op.value||op]; } if (!$.isEmptyObject(currentValues)) { + selected = opt.default || []; // Invalid, set to default/empty - this.value((opt.default||[]).join(",")); + this.value(selected.join(",")); } + that._updateOptionSelectLabel(selected); } } else { var selectedOption = this.optionValue||opt.options[0]; @@ -938,8 +964,6 @@ this.input.attr('type',this.defaultInputType) } if (opt.hasValue === false) { - this.oldValue = this.input.val(); - this.input.val(""); this.elementDiv.hide(); this.valueLabelContainer.hide(); } else if (opt.valueLabel) { @@ -952,10 +976,6 @@ this.elementDiv.hide(); opt.valueLabel.call(this,this.valueLabelContainer,this.input.val()); } else { - if (this.oldValue !== undefined) { - this.input.val(this.oldValue); - delete this.oldValue; - } this.valueLabelContainer.hide(); this.elementDiv.show(); } diff --git a/packages/node_modules/@node-red/editor-client/src/sass/ui/common/typedInput.scss b/packages/node_modules/@node-red/editor-client/src/sass/ui/common/typedInput.scss index 2b12fffea..a084fcff3 100644 --- a/packages/node_modules/@node-red/editor-client/src/sass/ui/common/typedInput.scss +++ b/packages/node_modules/@node-red/editor-client/src/sass/ui/common/typedInput.scss @@ -81,7 +81,8 @@ z-index: 2000; a { padding: 6px 18px 6px 6px; - display: block; + display: flex; + align-items: center; border-bottom: 1px solid $secondary-border-color; color: $form-text-color; &:hover { @@ -98,7 +99,7 @@ background: $workspace-button-background-active; } input[type="checkbox"] { - margin-right: 6px; + margin: 0 6px 0 0; } } .red-ui-typedInput-icon {