Support pasted "," radix point in Source Cash (Create Deposit) (#333)

This commit is contained in:
Rinat Arsaev 2024-02-22 12:58:37 +07:00 committed by GitHub
parent 4773475e55
commit 7e5ac50b8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -1,7 +1,7 @@
<div style="display: flex; gap: 8px">
<mat-form-field style="width: 100%">
<mat-label>{{ label || 'Amount' }}</mat-label>
<span matPrefix>{{ prefix }}&nbsp;</span>
<span matPrefix style="padding: 8px">{{ prefix }}&nbsp;</span>
<input
[formControl]="amountControl"
[inputMask]="amountMask$ | async"

View File

@ -36,6 +36,7 @@ export interface SourceCash {
}
const GROUP_SEPARATOR = ' ';
const RADIX_POINT = '.';
@Component({
standalone: true,
@ -83,9 +84,12 @@ export class SourceCashFieldComponent
createMask({
alias: 'numeric',
groupSeparator: GROUP_SEPARATOR,
radixPoint: RADIX_POINT,
digits: exponent,
digitsOptional: true,
placeholder: '',
onBeforePaste: (pastedValue: string) =>
this.convertPastedToStringNumber(pastedValue),
}),
),
shareReplay({ refCount: true, bufferSize: 1 }),
@ -109,6 +113,7 @@ export class SourceCashFieldComponent
}
ngOnInit() {
super.ngOnInit();
combineLatest([
combineLatest([getValueChanges(this.amountControl), this.currencyExponent$]).pipe(
map(([amountStr, exponent]) => {
@ -146,6 +151,7 @@ export class SourceCashFieldComponent
const { sourceId, amount } = value || {};
if (!sourceId) {
this.setValues(amount, null);
return;
}
this.options$
.pipe(
@ -179,4 +185,8 @@ export class SourceCashFieldComponent
typeof amount === 'number' ? String(toMajorByExponent(amount, exponent)) : null,
);
}
private convertPastedToStringNumber(pastedValue: string) {
return pastedValue.replaceAll(',', RADIX_POINT);
}
}