From 96dc266b8886a51a2c1658332668be059f77cf75 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Wed, 20 Nov 2024 11:31:50 +0300 Subject: [PATCH 1/3] $mol_number fix input --- number/number.view.ts | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/number/number.view.ts b/number/number.view.ts index b1360dbc4f9..1c74f500ada 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -6,13 +6,12 @@ namespace $.$$ { */ export class $mol_number extends $.$mol_number { - value_limited( next? : any ) : number { + value_limited( next? : string | number ) : number { if ( next === undefined ) return this.value() if ( next === '' ) return this.value( Number.NaN ) const min = this.value_min() const max = this.value_max() - const val = Number( next ) if( val < min ) return this.value( min ) @@ -28,23 +27,36 @@ namespace $.$$ { override event_inc( next? : Event ) { this.value_limited( ( this.value_limited() || 0 ) + this.precision_change() ) } - - override value_string( next? : string ) { - const next_num = this.value_limited( next ) - const precisionView = this.precision_view() + value_normalized(next?: string) { + const next_num = this.value_limited( next ) + if (Number.isNaN(next_num)) return '' + const precision_view = this.precision_view() if( next_num === 0 ) return '0' if( !next_num ) return '' - if( precisionView >= 1 ) { - return ( next_num / precisionView ).toFixed() + if( precision_view >= 1 ) { + return ( next_num / precision_view ).toFixed() } else { - const fixedNumber = Math.log10( 1 / precisionView ) - return next_num.toFixed( Math.ceil( fixedNumber ) ) + const fixed_number = Math.log10( 1 / precision_view ) + return next_num.toFixed( Math.ceil( fixed_number ) ) } } + @ $mol_mem + override value_string( next? : string ) { + const current = this.value_normalized() + + if ( next !== undefined) { + const normalized = this.value_normalized( next ) + if (normalized) return normalized + } + + return next ?? current + + } + @ $mol_mem override dec_enabled() : boolean { return this.enabled() && ( From ad14135f5210f42c79b4f4fec7282b7b90e1f7cb Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Wed, 20 Nov 2024 12:08:39 +0300 Subject: [PATCH 2/3] $mol_number limited only numbers --- number/number.view.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/number/number.view.ts b/number/number.view.ts index 1c74f500ada..7f4152fe2e2 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -6,13 +6,12 @@ namespace $.$$ { */ export class $mol_number extends $.$mol_number { - value_limited( next? : string | number ) : number { - if ( next === undefined ) return this.value() - if ( next === '' ) return this.value( Number.NaN ) + value_limited( val? : number ) : number { + if (Number.isNaN( val )) return this.value(val) + if ( val === undefined ) return this.value() const min = this.value_min() const max = this.value_max() - const val = Number( next ) if( val < min ) return this.value( min ) if( val > max ) return this.value( max ) @@ -29,8 +28,10 @@ namespace $.$$ { } value_normalized(next?: string) { - const next_num = this.value_limited( next ) + const next_num = this.value_limited( next === undefined ? next : Number(next) ) + if (Number.isNaN(next_num)) return '' + const precision_view = this.precision_view() if( next_num === 0 ) return '0' From 81842e65aa32b161d5c35ea7538b53c6626129de Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Wed, 20 Nov 2024 12:36:44 +0300 Subject: [PATCH 3/3] $mol_number ignore value on value_string input --- number/number.view.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/number/number.view.ts b/number/number.view.ts index 7f4152fe2e2..90285bbf3d5 100644 --- a/number/number.view.ts +++ b/number/number.view.ts @@ -49,10 +49,7 @@ namespace $.$$ { override value_string( next? : string ) { const current = this.value_normalized() - if ( next !== undefined) { - const normalized = this.value_normalized( next ) - if (normalized) return normalized - } + if ( next !== undefined) this.value_normalized( next ) return next ?? current