sidewayss / html-elements

Autonomous custom HTML elements with external template files
MIT License
0 stars 0 forks source link

Should keyboard input use locale for decimal point? #18

Closed sidewayss closed 1 day ago

sidewayss commented 3 days ago

The decimal point aka marker is the one locale-specific detail in a raw, unformatted number. Currently if, for example, your locale uses comma , for the decimal marker instead of period . the element will display the default period . during keyboard input.

See the useGrouping option for supressing thousands separators, which will leave the decimal marker alone. It will require testing to see how that non-standard decimal marker character performs while editing via keyboard.

I just tried this and neither parseFloat(), nor Number() handle comma as the decimal marker. There are workarounds, obviously. In this case there will be no thousands separators because of useGrouping:false, so it's safe to do the string replacement prior to converting to number. It should really check to see if the correct decimal marker character for the current locale is being used. That will be a small pain, but would allow you to know when to do the string replacement, which would be safer. Thankfully it looks like there are only two options for decimal marker, comma and period: https://www.bipm.org/en/committees/cg/cgpm/22-2003/resolution-10

sidewayss commented 1 day ago

Fixed by this commit and integrated with the new any-decimal/anyDecimal attribute/property.

Now keyboard input uses the locale's decimal marker, but with any-decimal it allows input of either comma or period.