Skip to content

Commit

Permalink
$mol_number Intl en locale
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Nov 23, 2024
1 parent 9849191 commit 29e7d0e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion number/number.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ $mol_number $mol_view
enabled true
sub /
<= String $mol_format
allow \0123456789.-
allow \0123456789,.-
mask* <= mask* \
- \ we don't want native number controls in mobile devices
- \ https://stackoverflow.com/questions/3790935/can-i-hide-the-html5-number-input-s-spin-box
Expand Down
12 changes: 7 additions & 5 deletions number/number.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace $.$$ {
if (next === undefined) return current

const minus = next.includes('-')
next = next.replace(/[^\d\.]/g, '')
next = next.replace(/,/g, '.').replace(/[^\d\.]/g, '')

if ( minus ) next = '-' + next
const dot_pos = next.indexOf('.')
Expand All @@ -67,15 +67,17 @@ namespace $.$$ {
}

@ $mol_mem
formatter() {
return new Intl.NumberFormat()
static formatter() {
return new Intl.NumberFormat('en-EN')
}

formatter() { return this.$.$mol_number.formatter() }

override mask(val: string) {
if (! val) return ''
const current = Number(val.replace(/[^\d\.\-]/g, ''))
const current = Number(val.replace(/,/g, '.').replace(/[^\d\.\-]/g, ''))
if (Number.isNaN(current)) return ''
return this.formatter().format(current).replace(/[^\s]/g, '_')
return this.formatter().format(current).replace(',', ' ').replace(/[^\s]/g, '_')
}

@ $mol_mem
Expand Down

0 comments on commit 29e7d0e

Please sign in to comment.