-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
numericFormatter locale issue #1503
numericFormatter locale issue #1503
Conversation
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat I think this is what we are looking for to solve this. |
I have added in a number formatter on both the formatNumericValue & unformatStringValue functions. The formatter is an object that is created from a given locale. This is how we determine how numbers are formatted. // Create a number formatter using the specified locale
const numberFormatter = new Intl.NumberFormat(params.formatterParams.locale); I then use the formatter to break down the number into parts (digits, decimal seprator etc.) const parts = numberFormatter.formatToParts(1.1); After that I find the decimal separator which is used in the locale, by looking for the 'decimal' type in the parts array. // Find the decimal separator used in this locale
const decimalSeperator = parts.find(part => part.type === 'decimal')?.value; Then we replace the locale-specific decimal separator in the stringValue with a period. This normalises the number so that Javascript can perform a parseFloat. // Replace the locale-specific decimal separator with a standard period
const normalisedValue = stringValue.replace(decimalSeperator, '.'); Then we replace any characters that aren't digits, periods, or minus signs. This will clean up thousand separators. // Remove any non-numeric characters, except for period and minus sign
const cleanedValue = normalisedValue.replace(/[^\d.-]/g, ''); |
Changes to how sliders get formatted as changed. The value coming from a slider to the numericInput function I have added in a flag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed one commit, the oninput
was not calling onRangeInput
correctly. I have updated it to this line of code:
oninput=${e => onRangeInput(e, params)}>`
I have tested this using English, German, French and Thai in XYZ and all working for me :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On an editable infoj entry, with a value of say 9999 - it is impossible to set this back to null. this should be possible.
This fails as CSS invalid gets applied so you can't save it.
When using a range slider on the infoj entry too, if the value is null - then the slider does not appear, which it should.
This is ready for re-review!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me. Icon scaling with default set with 2 decimals reformats ok. Also when editing numeric location fields incorrect separator is prevented 👍
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good with me now - thanks @RobAndrewHurst
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Description
The numeric formatter fails on slider element input elements for a user with a locale that uses comma decimals, eg. DE 🇩🇪
The comma seperator isn't displayed and the return is an integer instead of a float.
GitHub Issue
#1499
Type of Change
Testing Checklist