From a35653d35d07e7d122a77e04489aa23df8dd05e0 Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Thu, 11 May 2023 15:06:37 +0200 Subject: [PATCH] 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 --- CHANGELOG.md | 1 + modules/ui/fields/combo.js | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34b0d03e0..19a81babc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ _Breaking developer changes, which may affect downstream projects or sites that * Fix `multi/many/semiCombo` options for not being selectable immediately after removing them for fields with predefined options * Fix a bug where the _Add_ input element on comboboxes with a fixed set of allowed options is still hidden after an option of a previously "fully saturated" field is removed * Fix wrongly flagged "incorrect geometry type" warnings for features with lifecycle-prefixed tags ([#9483], thanks [@biswajit-k]) +* Fix corruption of tag values of fields with referenced strings, but restricted `options`, when an unavailable option is entered manually into the field. #### :earth_asia: Localization * Send `Accept-Language` header on Nominatim API calls ([#9501], thanks [@k-yle]) * Add Address and Phone Format for India ([#9482], thanks [@biswajit-k]) diff --git a/modules/ui/fields/combo.js b/modules/ui/fields/combo.js index d4374bd93..45af9aff8 100644 --- a/modules/ui/fields/combo.js +++ b/modules/ui/fields/combo.js @@ -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,