fix persian number in input
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user