refresh numeric fields on blur (#11027)

This commit is contained in:
Martin Raifer
2025-05-12 18:09:39 +02:00
committed by GitHub
parent 9b7a98862d
commit 7f8e676af3
2 changed files with 24 additions and 8 deletions
+2
View File
@@ -43,12 +43,14 @@ _Breaking developer changes, which may affect downstream projects or sites that
#### :camera: Street-Level
#### :white_check_mark: Validation
#### :bug: Bugfixes
* Refresh numeric input fields after leaving focus with the value that is stored in the tag ([#11027])
#### :earth_asia: Localization
#### :hourglass: Performance
#### :mortar_board: Walkthrough / Help
#### :hammer: Development
[#10970]: https://github.com/openstreetmap/iD/pull/10970
[#11027]: https://github.com/openstreetmap/iD/pull/11027
# v2.34.0
+22 -8
View File
@@ -414,19 +414,33 @@ export function uiFieldText(field, context) {
// don't override multiple values with blank string
if (!val && getVals(_tags).size > 1) return;
var displayVal = val;
let displayVal = val;
if (field.type === 'number' && val) {
var numbers = val.split(';');
numbers = numbers.map(function(v) {
const numbers = val.split(';').map(v => {
if (likelyRawNumberFormat.test(v)) {
// input number likely in "raw" format
return v;
return {
v,
num: parseFloat(v),
fractionDigits: v.includes('.') ? v.split('.')[1].length : 0
};
} else {
// try to parse in localized number format
return {
v,
num: parseLocaleFloat(v),
fractionDigits: countDecimalPlaces(v)
};
}
var num = parseLocaleFloat(v);
const fractionDigits = countDecimalPlaces(v);
return isFinite(num) ? clamped(num).toFixed(fractionDigits) : v;
});
val = numbers.join(';');
val = numbers.map(({num, v, fractionDigits}) => {
if (!isFinite(num)) return v;
return clamped(num).toFixed(fractionDigits);
}).join(';');
displayVal = numbers.map(({num, v, fractionDigits}) => {
if (!isFinite(num)) return v;
return formatFloat(clamped(num), fractionDigits);
}).join(';');
}
if (!onInput) utilGetSetValue(input, displayVal);
t[field.key] = val || undefined;