From 880c48676dba7c57f9a7cf82fac87ad2e609fa97 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 17 Mar 2023 17:15:58 +0800 Subject: [PATCH] fix(nc-gui): vModel on numeric columns --- packages/nc-gui/components/cell/Decimal.vue | 20 ++++++++++++++++++-- packages/nc-gui/components/cell/Float.vue | 20 ++++++++++++++++++-- packages/nc-gui/components/cell/Integer.vue | 20 ++++++++++++++++++-- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/packages/nc-gui/components/cell/Decimal.vue b/packages/nc-gui/components/cell/Decimal.vue index cdcb0d4bdb..abade14fb7 100644 --- a/packages/nc-gui/components/cell/Decimal.vue +++ b/packages/nc-gui/components/cell/Decimal.vue @@ -3,7 +3,10 @@ import type { VNodeRef } from '@vue/runtime-core' import { EditModeInj, inject, useVModel } from '#imports' interface Props { - modelValue?: number | null + // when we set a number, then it is number type + // for sqlite, when we clear a cell or empty the cell, it returns "" + // otherwise, it is null type + modelValue?: number | null | string } interface Emits { @@ -18,7 +21,20 @@ const { showNull } = useGlobal() const editEnabled = inject(EditModeInj) -const vModel = useVModel(props, 'modelValue', emits) +const _vModel = useVModel(props, 'modelValue', emits) + +const vModel = computed({ + get: () => _vModel.value, + set: (value) => { + if (value === '') { + // if we clear / empty a cell in sqlite, + // the value is considered as '' + _vModel.value = null + } else { + _vModel.value = value + } + }, +}) const focus: VNodeRef = (el) => (el as HTMLInputElement)?.focus() diff --git a/packages/nc-gui/components/cell/Float.vue b/packages/nc-gui/components/cell/Float.vue index 6a97f12abb..b490854e1c 100644 --- a/packages/nc-gui/components/cell/Float.vue +++ b/packages/nc-gui/components/cell/Float.vue @@ -3,7 +3,10 @@ import type { VNodeRef } from '@vue/runtime-core' import { EditModeInj, inject, useVModel } from '#imports' interface Props { - modelValue?: number | null + // when we set a number, then it is number type + // for sqlite, when we clear a cell or empty the cell, it returns "" + // otherwise, it is null type + modelValue?: number | null | string } interface Emits { @@ -18,7 +21,20 @@ const { showNull } = useGlobal() const editEnabled = inject(EditModeInj) -const vModel = useVModel(props, 'modelValue', emits) +const _vModel = useVModel(props, 'modelValue', emits) + +const vModel = computed({ + get: () => _vModel.value, + set: (value) => { + if (value === '') { + // if we clear / empty a cell in sqlite, + // the value is considered as '' + _vModel.value = null + } else { + _vModel.value = value + } + }, +}) const focus: VNodeRef = (el) => (el as HTMLInputElement)?.focus() diff --git a/packages/nc-gui/components/cell/Integer.vue b/packages/nc-gui/components/cell/Integer.vue index 0b12b3a90d..e70b83f240 100644 --- a/packages/nc-gui/components/cell/Integer.vue +++ b/packages/nc-gui/components/cell/Integer.vue @@ -3,7 +3,10 @@ import type { VNodeRef } from '@vue/runtime-core' import { EditModeInj, inject, useVModel } from '#imports' interface Props { - modelValue?: number | null + // when we set a number, then it is number type + // for sqlite, when we clear a cell or empty the cell, it returns "" + // otherwise, it is null type + modelValue?: number | null | string } interface Emits { @@ -18,7 +21,20 @@ const { showNull } = useGlobal() const editEnabled = inject(EditModeInj) -const vModel = useVModel(props, 'modelValue', emits) +const _vModel = useVModel(props, 'modelValue', emits) + +const vModel = computed({ + get: () => _vModel.value, + set: (value) => { + if (value === '') { + // if we clear / empty a cell in sqlite, + // the value is considered as '' + _vModel.value = null + } else { + _vModel.value = value + } + }, +}) const focus: VNodeRef = (el) => (el as HTMLInputElement)?.focus()