Allow negative toman input for SMS auto-block threshold.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import {
|
||||
fromGroupedInput,
|
||||
rialToToman,
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
* Money field bound to **rial** storage values (API/DB).
|
||||
* User types and sees **toman** (÷10 / ×10 at the edges).
|
||||
* With `nullable`, empty input emits `null` (for optional thresholds).
|
||||
* With `allowNegative`, values like `-50,000` are accepted.
|
||||
*/
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
@@ -34,7 +35,18 @@ const emit = defineEmits<{
|
||||
(e: 'update:value', value: number | null): void
|
||||
}>()
|
||||
|
||||
/** Keeps intermediate input like "-" while typing a negative amount. */
|
||||
const draft = ref<string | null>(null)
|
||||
|
||||
watch(
|
||||
() => props.value,
|
||||
() => {
|
||||
draft.value = null
|
||||
},
|
||||
)
|
||||
|
||||
const display = computed(() => {
|
||||
if (draft.value !== null) return draft.value
|
||||
if (props.nullable && (props.value == null || props.value === undefined)) return ''
|
||||
return toGroupedDisplay(rialToToman(props.value ?? 0))
|
||||
})
|
||||
@@ -42,9 +54,16 @@ const display = computed(() => {
|
||||
function onInput(raw: string | number) {
|
||||
const text = String(raw ?? '').trim()
|
||||
if (props.nullable && !text) {
|
||||
draft.value = null
|
||||
emit('update:value', null)
|
||||
return
|
||||
}
|
||||
// Allow typing a leading minus before digits arrive.
|
||||
if (props.allowNegative && text === '-') {
|
||||
draft.value = '-'
|
||||
return
|
||||
}
|
||||
draft.value = null
|
||||
const toman = fromGroupedInput(text, props.allowNegative)
|
||||
emit('update:value', tomanToRial(toman))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user