diff --git a/CHANGELOG.md b/CHANGELOG.md index 87c99f6cc..8b56b93d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ _Breaking developer changes, which may affect downstream projects or sites that * Fix icons with inline css styles not properly being displayed on osm.org * Properly sort map features with lifecycle prefixes in the _Past/Futures_ features ([#7582]) * Only consider features with either `landuse`, `natural`, `amentiy` or `leisure` tag to be classified as _Landuse_ areas +* Fix address field overwriting existing data when switching selected map features under certain circumstances ([#10260]) #### :earth_asia: Localization #### :hourglass: Performance #### :mortar_board: Walkthrough / Help @@ -68,6 +69,7 @@ _Breaking developer changes, which may affect downstream projects or sites that [#10181]: https://github.com/openstreetmap/iD/pull/10181 [#10255]: https://github.com/openstreetmap/iD/pull/10255 [#10257]: https://github.com/openstreetmap/iD/pull/10257 +[#10260]: https://github.com/openstreetmap/iD/issues/10260 [@zbycz]: https://github.com/zbycz diff --git a/modules/ui/fields/address.js b/modules/ui/fields/address.js index bbde62162..27cdbb1d1 100644 --- a/modules/ui/fields/address.js +++ b/modules/ui/fields/address.js @@ -6,7 +6,7 @@ import { presetManager } from '../../presets'; import { fileFetcher } from '../../core/file_fetcher'; import { geoExtent, geoChooseEdge, geoSphericalDistance } from '../../geo'; import { uiCombobox } from '../combobox'; -import { utilArrayUniqBy, utilGetSetValue, utilNoAuto, utilRebind, utilTotalExtent } from '../../util'; +import { utilArrayUniqBy, utilGetSetValue, utilNoAuto, utilRebind, utilTotalExtent, utilTriggerEvent } from '../../util'; import { t } from '../../core/localizer'; @@ -235,6 +235,7 @@ export function uiFieldAddress(field, context) { if (d.isAutoStreetPlace) { // set subtag depending on selected entry d.id = selected ? selected.type : 'street'; + utilTriggerEvent(d3_select(this), 'change'); } }) ); @@ -283,35 +284,33 @@ export function uiFieldAddress(field, context) { function change(onInput) { return function() { - setTimeout(() => { - var tags = {}; + var tags = {}; - _wrap.selectAll('input') - .each(function (subfield) { - var key = field.key + ':' + subfield.id; + _wrap.selectAll('input') + .each(function (subfield) { + var key = field.key + ':' + subfield.id; - var value = this.value; - if (!onInput) value = context.cleanTagValue(value); + var value = this.value; + if (!onInput) value = context.cleanTagValue(value); - // don't override multiple values with blank string - if (Array.isArray(_tags[key]) && !value) return; + // don't override multiple values with blank string + if (Array.isArray(_tags[key]) && !value) return; - if (subfield.isAutoStreetPlace) { - if (subfield.id === 'street') { - tags[`${field.key}:place`] = undefined; - } else if (subfield.id === 'place') { - tags[`${field.key}:street`] = undefined; - } + if (subfield.isAutoStreetPlace) { + if (subfield.id === 'street') { + tags[`${field.key}:place`] = undefined; + } else if (subfield.id === 'place') { + tags[`${field.key}:street`] = undefined; } + } - tags[key] = value || undefined; - }); + tags[key] = value || undefined; + }); - Object.keys(tags) - .filter(k => tags[k]) - .forEach(k => _tags[k] = tags[k]); - dispatch.call('change', this, tags, onInput); - }, 0); + Object.keys(tags) + .filter(k => tags[k]) + .forEach(k => _tags[k] = tags[k]); + dispatch.call('change', this, tags, onInput); }; }