From 42ea10d30a831bde27aca2b3969ac751ada47481 Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Tue, 3 Jun 2025 20:44:48 +0200 Subject: [PATCH] properly update number fields with non-numeric values fixes a bug where the field was not properly filled in when the tag contained a non-numeric value (e.g. `direction=S`), which could eventually cause the tag be deleted inadvertently after focussing/blurring the field. closes #11076 this regressed in 2b64d703523a2856bd41b894dff9fcd5dc4bdc75 --- CHANGELOG.md | 2 ++ modules/ui/fields/input.js | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c76f8b2b4..89bde2e70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ _Breaking developer changes, which may affect downstream projects or sites that * Refresh numeric input fields after leaving focus with the value that is stored in the tag ([#11027]) * Fix oneway field falsely showing "Assumed to be Yes" if cycled through all options back to the default state * Fix false positives in "unreachable oneway" validation when `oneway=-1` tag is present ([#11068]) +* Fix a bug which can cause non-numeric values in tags of numeric input fields to not be displayed and potentially inadvertently cleared ([#11076]) #### :earth_asia: Localization #### :hourglass: Performance #### :mortar_board: Walkthrough / Help @@ -62,6 +63,7 @@ _Breaking developer changes, which may affect downstream projects or sites that [#11027]: https://github.com/openstreetmap/iD/pull/11027 [#11054]: https://github.com/openstreetmap/iD/issues/1104 [#11068]: https://github.com/openstreetmap/iD/issues/11068 +[#11076]: https://github.com/openstreetmap/iD/issues/11076 [@keiffer213]: https://github.com/keiffer213 [@haipq07]: https://github.com/haipq07 diff --git a/modules/ui/fields/input.js b/modules/ui/fields/input.js index 8bee5df31..0ac6fca64 100644 --- a/modules/ui/fields/input.js +++ b/modules/ui/fields/input.js @@ -501,12 +501,18 @@ export function uiFieldText(field, context) { // by pressing the +/- buttons or using the raw tag editor), we // can and should update the content of the input element. shouldUpdate = (inputValue, setValue) => { - const inputNums = inputValue.split(';').map(setVal => - likelyRawNumberFormat.test(setVal) - ? parseFloat(setVal) - : parseLocaleFloat(setVal) - ); - const setNums = setValue.split(';').map(parseLocaleFloat); + const inputNums = inputValue.split(';').map(val => { + const parsedNum = likelyRawNumberFormat.test(val) + ? parseFloat(val) + : parseLocaleFloat(val); + if (!isFinite(parsedNum)) return val; // keep unparsable values as-is + return parsedNum; + }); + const setNums = setValue.split(';').map(val => { + const parsedNum = parseLocaleFloat(val); + if (!isFinite(parsedNum)) return val; // keep unparsable values as-is + return parsedNum; + }); return !isEqual(inputNums, setNums); }; }