Et2Number: Pad number with specific mask to full number of decimals

This commit is contained in:
nathan 2024-08-06 11:52:22 -06:00
parent 05b983ab1c
commit 5cfc165f1d
2 changed files with 19 additions and 3 deletions

View File

@ -240,7 +240,7 @@ export class Et2Number extends Et2Textbox
get valueAsNumber() : number get valueAsNumber() : number
{ {
let formattedValue = this._mask?.unmaskedValue ?? this.value; let formattedValue = (this.mask && this._mask?.value ? this.stripFormat(this._mask.value) : this._mask?.unmaskedValue) ?? this.value;
if(typeof this.precision !== 'undefined') if(typeof this.precision !== 'undefined')
{ {
formattedValue = parseFloat(parseFloat(<string>formattedValue).toFixed(this.precision)); formattedValue = parseFloat(parseFloat(<string>formattedValue).toFixed(this.precision));
@ -318,7 +318,23 @@ export class Et2Number extends Et2Textbox
updateMaskValue() updateMaskValue()
{ {
this._mask.updateValue(); this._mask.updateValue();
this._mask.unmaskedValue = "" + this.value; if(!this.mask)
{
// Number mask sometimes gets lost with different decimal characters
this._mask.unmaskedValue = ("" + this.value);
// Fill decimals to precision
if(this.precision && ("" + this.value).includes("."))
{
this._mask.unmaskedValue = this._mask.unmaskedValue.padEnd(("" + this.value).length + this.precision, "0");
}
}
else if(this.precision && ("" + this.value).includes("."))
{
// Fill decimals to precision
let v = formatNumber(this.value, this.decimalSeparator, this.thousandsSeparator);
this._mask.value = v.padEnd(v.length + this.precision, "0");
}
this._mask.updateValue(); this._mask.updateValue();
} }

View File

@ -72,7 +72,7 @@ export class Et2Textbox extends Et2InputWidget(SlInput)
onkeypress; onkeypress;
private __validator : any; private __validator : any;
private _mask : InputMask; protected _mask : InputMask;
protected _value : string = ""; protected _value : string = "";
inputMode = "text"; inputMode = "text";