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 2b64d70352
This commit is contained in:
Martin Raifer
2025-06-03 20:44:48 +02:00
parent 5cb19f2cb1
commit 42ea10d30a
2 changed files with 14 additions and 6 deletions
+2
View File
@@ -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
+12 -6
View File
@@ -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);
};
}