From 98dd3825a8e44b2f75d8d8626e7afa1e9fa33ec4 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Sat, 23 Nov 2024 20:50:37 +0300 Subject: [PATCH] $mol_number dot minus constraint --- number/number.view.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/number/number.view.ts b/number/number.view.ts index 90285bbf3d5..2a9399d20a0 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -7,7 +7,7 @@ namespace $.$$ { export class $mol_number extends $.$mol_number { value_limited( val? : number ) : number { - if (Number.isNaN( val )) return this.value(val) + if (Number.isNaN( val )) return this.value( val ) if ( val === undefined ) return this.value() const min = this.value_min() @@ -28,7 +28,7 @@ namespace $.$$ { } value_normalized(next?: string) { - const next_num = this.value_limited( next === undefined ? next : Number(next) ) + const next_num = this.value_limited( next === undefined ? next : Number(next || Number.NaN) ) if (Number.isNaN(next_num)) return '' @@ -48,13 +48,24 @@ namespace $.$$ { @ $mol_mem override value_string( next? : string ) { const current = this.value_normalized() + if (next === undefined) return current - if ( next !== undefined) this.value_normalized( next ) + const minus = next.includes('-') + next = next.replace(/[^\d\.]/g, '') + + if ( minus ) next = '-' + next + const dot_pos = next.indexOf('.') + + if (dot_pos !== -1) { + next = next.slice(0, dot_pos) + '.' + next.slice(dot_pos + 1).replace(/\./g, '') + } + + this.value_normalized( next ) return next ?? current } - + @ $mol_mem override dec_enabled() : boolean { return this.enabled() && (