Use _ADD_ value for add... and none options

This commit is contained in:
GogoVega 2024-06-25 20:08:31 +02:00
parent 5a75440668
commit f75e2f221c
No known key found for this signature in database
GPG Key ID: E1E048B63AC5AC2B

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);