diff --git a/CHANGELOG.md b/CHANGELOG.md index 694279da1..a6dcf837d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/modules/ui/fields/input.js b/modules/ui/fields/input.js index 04edf2a40..8bee5df31 100644 --- a/modules/ui/fields/input.js +++ b/modules/ui/fields/input.js @@ -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;