Skip to content

Commit b284582

Browse files
committed
fix: update decimal input handling to improve user experience
1 parent e9fb9ca commit b284582

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

adminforth/spa/src/components/ColumnValueInput.vue

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,21 @@
9292
<Input
9393
v-else-if="(type || column.type) === 'decimal'"
9494
ref="input"
95-
type="number"
95+
type="text"
9696
inputmode="decimal"
9797
class="w-40"
98-
placeholder="0.0"
99-
:fullWidth="true"
100-
:prefix="column.inputPrefix"
101-
:suffix="column.inputSuffix"
102-
:modelValue="String(value)"
103-
@update:modelValue="$emit('update:modelValue', String($event))"
98+
:modelValue="isEditing ? value : cleanDecimalValue(value)"
99+
@focus="() => {
100+
isEditing = true;
101+
$emit('update:modelValue', cleanDecimalValue(value));
102+
}"
103+
@update:modelValue="val => $emit('update:modelValue', val.replace(',', '.').replace(/[^\d.]/g, ''))"
104+
@blur="() => {
105+
isEditing = false;
106+
$emit('update:modelValue', cleanDecimalValue(value));
107+
}"
104108
/>
105-
<Input
109+
<Input
106110
v-else-if="(type || column.type) === 'float'"
107111
ref="input"
108112
type="number"
@@ -209,6 +213,8 @@
209213
const loadMoreOptions = inject('loadMoreOptions', (() => {}) as any);
210214
211215
const input = ref<HTMLInputElement | null>(null);
216+
const isEditing = ref(false);
217+
const cleanDecimalValue = (v: any) => v?.toString().replace(/(\.[0-9]*[1-9])0+$|\.0+$/, '$1') || '';
212218
213219
const getBooleanOptions = (column: any) => {
214220
const options: Array<{ label: string; value: boolean | null }> = [

0 commit comments

Comments
 (0)