use all available option strings when setting value

this fixes where tag values of fields with referenced strings can become corrupted when the sub-field has restricted `options`, and an unavailable option is entered manually into the field.

important for openstreetmap/id-tagging-schema#891
This commit is contained in:
Martin Raifer
2023-05-11 15:06:37 +02:00
parent f9aa675637
commit a35653d35d
2 changed files with 10 additions and 3 deletions
+9 -3
View File
@@ -73,7 +73,7 @@ export function uiFieldCombo(field, context) {
function tagValue(dval) {
dval = clean(dval || '');
var found = getOptions().find(function(o) {
var found = getOptions(true).find(function(o) {
return o.key && clean(o.value) === dval;
});
if (found) return found.key;
@@ -171,11 +171,17 @@ export function uiFieldCombo(field, context) {
}
}
function getOptions() {
function getOptions(allOptions) {
var stringsField = field.resolveReference('stringsCrossReference');
if (!(field.options || stringsField.options)) return [];
return (field.options || stringsField.options).map(function(v) {
let options;
if (allOptions !== true) {
options = field.options || stringsField.options;
} else {
options = [].concat(field.options, stringsField.options).filter(Boolean);
}
return options.map(function(v) {
const labelId = getLabelId(stringsField, v);
return {
key: v,