Merge pull request #4800 from GogoVega/fix-config-select

Use `_ADD_` value for both `add new...` and `none` options
This commit is contained in:
Nick O'Leary 2024-06-26 10:51:39 +01:00 committed by GitHub
commit 830e475969
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -413,11 +413,8 @@ RED.editor = (function() {
if (selectedOpt?.data('env')) {
disableButton(addButton, true);
disableButton(editButton, true);
// disable the edit button if no options available
} else if (optionsLength === 1 && selectedOpt.val() === "_ADD_") {
disableButton(addButton, false);
disableButton(editButton, true);
} else if (selectedOpt.val() === "") {
// disable the edit button if no options available or 'none' selected
} else if (optionsLength === 1 || selectedOpt.val() === "_ADD_") {
disableButton(addButton, false);
disableButton(editButton, true);
} else {
@ -426,13 +423,9 @@ RED.editor = (function() {
}
});
const optionCount = select.find("option").length
if (optionCount === 1) {
// We only have the 'add new...' option
select.val('_ADD_')
} else {
select.val(nodeValue);
}
// If the value is "", 'add new...' option if no config node available or 'none' option
// Otherwise, it's a config node
select.val(nodeValue || '_ADD_');
}
/**
@ -933,9 +926,11 @@ RED.editor = (function() {
}
if (!configNodes.length) {
// Add 'add new...' option
select.append('<option value="_ADD_" selected>' + RED._("editor.addNewType", { type: label }) + '</option>');
} else {
select.append('<option value="">' + RED._("editor.inputs.none") + '</option>');
// Add 'none' option
select.append('<option value="_ADD_">' + RED._("editor.inputs.none") + '</option>');
}
window.setTimeout(function() { select.trigger("change");},50);