feat: update app version in ngsw-config.json; refactor input component for leading zero normalization and improve payment dialog handling
This commit is contained in:
@@ -41,6 +41,7 @@ import { ToggleSwitch } from 'primeng/toggleswitch';
|
||||
templateUrl: './input.component.html',
|
||||
})
|
||||
export class InputComponent {
|
||||
private lastValidNumericValue = '';
|
||||
@Input() type:
|
||||
| 'simple'
|
||||
| 'postalCode'
|
||||
@@ -226,6 +227,21 @@ export class InputComponent {
|
||||
return `${normalizedInteger}.${fixedDecimal}`;
|
||||
}
|
||||
|
||||
private normalizeLeadingZeros(value: string, allowDecimal: boolean): string {
|
||||
if (!value) return value;
|
||||
if (!allowDecimal) {
|
||||
return value.replace(/^0+(?=\d)/, '');
|
||||
}
|
||||
|
||||
if (value.includes('.')) {
|
||||
const [integerPart = '0', decimalPart = ''] = value.split('.');
|
||||
const normalizedInteger = integerPart.replace(/^0+(?=\d)/, '') || '0';
|
||||
return `${normalizedInteger}.${decimalPart}`;
|
||||
}
|
||||
|
||||
return value.replace(/^0+(?=\d)/, '');
|
||||
}
|
||||
|
||||
onInput($event: Event, isPriceFormat?: boolean) {
|
||||
const target = $event.target as HTMLInputElement | null;
|
||||
if (!target) return;
|
||||
@@ -236,6 +252,7 @@ export class InputComponent {
|
||||
if (this.inputMode === 'numeric' || this.inputMode === 'decimal' || isPriceFormat) {
|
||||
value = this.sanitizeNumericValue(value, allowDecimal);
|
||||
value = this.applyFixed(value);
|
||||
value = this.normalizeLeadingZeros(value, allowDecimal);
|
||||
}
|
||||
|
||||
if (this.preparedMaxLength && value.length > this.preparedMaxLength) {
|
||||
@@ -260,12 +277,23 @@ export class InputComponent {
|
||||
text: `مقدار ${this.label} نمیتواند کمتر از ${this.min} باشد.`,
|
||||
});
|
||||
}
|
||||
value = value.slice(0, -1);
|
||||
value = this.lastValidNumericValue;
|
||||
numericValue = Number.isNaN(parseFloat(value)) ? 0 : parseFloat(value);
|
||||
|
||||
const isIdentifierField = ['mobile', 'phone', 'postalCode', 'nationalId'].includes(this.type);
|
||||
const restoredControlValue = isIdentifierField ? value : value === '' ? '' : numericValue;
|
||||
|
||||
this.control.setValue(restoredControlValue);
|
||||
target.value = isPriceFormat && value !== '' ? numericValue.toLocaleString('en-US') : value;
|
||||
return;
|
||||
} else if (this.inputMode === 'numeric' || this.inputMode === 'decimal') {
|
||||
this.lastValidNumericValue = value;
|
||||
}
|
||||
|
||||
const isIdentifierField = !this.numericValue;
|
||||
this.control.setValue(isIdentifierField ? value : value === '' ? '' : numericValue);
|
||||
const isIdentifierField = ['mobile', 'phone', 'postalCode', 'nationalId'].includes(this.type);
|
||||
const controlValue = isIdentifierField ? value : value === '' ? '' : numericValue;
|
||||
|
||||
this.control.setValue(controlValue);
|
||||
|
||||
const viewValue = isPriceFormat && value !== '' ? numericValue.toLocaleString('en-US') : value;
|
||||
|
||||
@@ -277,4 +305,10 @@ export class InputComponent {
|
||||
this.valueChange.emit(isIdentifierField ? value : numericValue);
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
const allowDecimal = this.type === 'price' || this.type === 'number';
|
||||
const initial = this.sanitizeNumericValue(`${this.control?.value ?? ''}`, allowDecimal);
|
||||
this.lastValidNumericValue = initial;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user