fix persian number in input

This commit is contained in:
2026-08-14 21:05:11 +03:30
parent 82dc6b82d8
commit 2b27b16296
10 changed files with 160 additions and 123 deletions
@@ -91,7 +91,7 @@
:disabled="disabled"
class="w-full"
:formatter="(v: string) => `${v}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')"
:parser="(v: string) => v.replace(/,/g, '')"
:parser="(v: string) => sanitizeNumericString(v, { allowDecimal: false })"
@update:value="onPriceChange"
/>
@@ -144,6 +144,7 @@ import {
switchValueFromChecked,
type SettingFieldType
} from './settingTypes'
import { parseNumericValue, sanitizeNumericString } from '@core/utils/convert'
import dayjs, { type Dayjs } from 'dayjs'
import customParseFormat from 'dayjs/plugin/customParseFormat'
@@ -234,7 +235,7 @@ function onTimeChange(val: Dayjs | string | null | undefined) {
}
const priceValue = computed(() => {
const n = parseFloat(String(props.modelValue || '').replace(/,/g, ''))
const n = parseNumericValue(props.modelValue || '')
return Number.isFinite(n) ? n : undefined
})
@@ -243,25 +244,11 @@ function onPriceChange(val: number | string | null) {
emit('update:value', '')
return
}
emit('update:value', String(val))
}
function normalizePlainNumberInput(value: string): string {
const latin = value.replace(/[۰-۹]/g, (d) => String('۰۱۲۳۴۵۶۷۸۹'.indexOf(d)))
let out = ''
let hasDot = false
for (const ch of latin.replace(/,/g, '')) {
if (ch >= '0' && ch <= '9') out += ch
else if (ch === '.' && !hasDot) {
hasDot = true
out += ch
}
}
return out
emit('update:value', sanitizeNumericString(val, { allowDecimal: false }))
}
function onPlainNumberChange(val: string) {
emit('update:value', normalizePlainNumberInput(val ?? ''))
emit('update:value', sanitizeNumericString(val ?? '', { allowDecimal: true }))
}
</script>
@@ -1,5 +1,6 @@
import type { Const } from '@/model/configuration'
import { conditionalOrderEnabledSetting, isStoreApp, priceChannelAccessSetting, priceProviderSetting, showToUsersChatSetting } from '@/utils/config'
import { sanitizeNumericString } from '@core/utils/convert'
export type SettingFieldType =
| 'text'
@@ -517,10 +518,10 @@ export function formatValueForSave(
)
}
if (type === 'price') {
return value === '' ? '0' : String(value).replace(/,/g, '')
return value === '' ? '0' : sanitizeNumericString(value, { allowDecimal: false })
}
if (type === 'number') {
return String(value ?? '').replace(/,/g, '')
return sanitizeNumericString(value ?? '', { allowDecimal: true })
}
if (type === 'time') {
return normalizeTimeValue(value)