diff --git a/packages/nc-gui/components/smartsheet/Form.vue b/packages/nc-gui/components/smartsheet/Form.vue index ac60e4e635..22eff7cdc8 100644 --- a/packages/nc-gui/components/smartsheet/Form.vue +++ b/packages/nc-gui/components/smartsheet/Form.vue @@ -236,7 +236,7 @@ function isDbRequired(column: Record) { // column required / not null column.rqd && // column default value - !column.cdf && + !isValidValue(column?.cdf) && // confirm it's not foreign key !columns.value.some( (c: Record) => diff --git a/packages/nc-gui/components/smartsheet/column/DefaultValue.vue b/packages/nc-gui/components/smartsheet/column/DefaultValue.vue index 74ea13d5cf..a383142538 100644 --- a/packages/nc-gui/components/smartsheet/column/DefaultValue.vue +++ b/packages/nc-gui/components/smartsheet/column/DefaultValue.vue @@ -32,7 +32,7 @@ const updateCdfValue = (cdf: string | null) => { } onMounted(() => { - updateCdfValue(vModel.value?.cdf ? vModel.value.cdf : null) + updateCdfValue(vModel.value?.cdf ?? null) }) watch( diff --git a/packages/nc-gui/components/smartsheet/column/EditOrAdd.vue b/packages/nc-gui/components/smartsheet/column/EditOrAdd.vue index 7b1c191543..3928d4478b 100644 --- a/packages/nc-gui/components/smartsheet/column/EditOrAdd.vue +++ b/packages/nc-gui/components/smartsheet/column/EditOrAdd.vue @@ -82,11 +82,11 @@ const showHoverEffectOnSelectedType = ref(true) const isVisibleDefaultValueInput = computed({ get: () => { - if (formState.value.cdf && !showDefaultValueInput.value) { + if (isValidValue(formState.value.cdf) && !showDefaultValueInput.value) { showDefaultValueInput.value = true } - return formState.value.cdf !== null || showDefaultValueInput.value + return isValidValue(formState.value.cdf) || showDefaultValueInput.value }, set: (value: boolean) => { showDefaultValueInput.value = value diff --git a/packages/nc-gui/composables/useData.ts b/packages/nc-gui/composables/useData.ts index 859eeed930..69227e59f7 100644 --- a/packages/nc-gui/composables/useData.ts +++ b/packages/nc-gui/composables/useData.ts @@ -284,7 +284,7 @@ export function useData(args: { col.uidt === UITypes.LastModifiedBy || col.uidt === UITypes.Lookup || col.au || - (col.cdf && / on update /i.test(col.cdf))) + (isValidValue(col?.cdf) && / on update /i.test(col.cdf))) ) acc[col.title!] = updatedRowData[col.title!] return acc diff --git a/packages/nc-gui/composables/useSharedFormViewStore.ts b/packages/nc-gui/composables/useSharedFormViewStore.ts index e68be73575..77452e031a 100644 --- a/packages/nc-gui/composables/useSharedFormViewStore.ts +++ b/packages/nc-gui/composables/useSharedFormViewStore.ts @@ -116,7 +116,7 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share !isAttachment(c) && c.uidt !== UITypes.SpecificDBType && c?.title && - c?.cdf && + isValidValue(c?.cdf) && !/^\w+\(\)|CURRENT_TIMESTAMP$/.test(c.cdf) ) { const defaultValue = typeof c.cdf === 'string' ? c.cdf.replace(/^'|'$/g, '') : c.cdf diff --git a/packages/nc-gui/utils/columnUtils.ts b/packages/nc-gui/utils/columnUtils.ts index dd643033b3..a69aa594b9 100644 --- a/packages/nc-gui/utils/columnUtils.ts +++ b/packages/nc-gui/utils/columnUtils.ts @@ -177,7 +177,7 @@ const getUIDTIcon = (uidt: UITypes | string) => { // 1. column not having default value // 2. column is not auto increment // 3. column is not auto generated -const isColumnRequired = (col?: ColumnType) => col && col.rqd && !col.cdf && !col.ai && !col.meta?.ag +const isColumnRequired = (col?: ColumnType) => col && col.rqd && !isValidValue(col?.cdf) && !col.ai && !col.meta?.ag const isVirtualColRequired = (col: ColumnType, columns: ColumnType[]) => col.uidt === UITypes.LinkToAnotherRecord && diff --git a/packages/nc-gui/utils/dataUtils.ts b/packages/nc-gui/utils/dataUtils.ts index 1943003616..b0cbdd6a3d 100644 --- a/packages/nc-gui/utils/dataUtils.ts +++ b/packages/nc-gui/utils/dataUtils.ts @@ -3,6 +3,26 @@ import type { ColumnType, LinkToAnotherRecordType, TableType } from 'nocodb-sdk' import { isColumnRequiredAndNull } from './columnUtils' import type { Row } from '~/lib/types' +export const isValidValue = (val: unknown) => { + if (val === null || val === undefined) { + return false + } + + if (typeof val === 'string' && val === '') { + return false + } + + if (Array.isArray(val) && val.length === 0) { + return false + } + + if (typeof val === 'object' && !Array.isArray(val) && Object.keys(val).length === 0) { + return false + } + + return true +} + export const extractPkFromRow = (row: Record, columns: ColumnType[]) => { if (!row || !columns) return null @@ -105,7 +125,7 @@ export const rowDefaultData = (columns: ColumnType[] = []) => { !isSystemColumn(col) && !isVirtualCol(col) && ![UITypes.Rollup, UITypes.Lookup, UITypes.Formula, UITypes.Barcode, UITypes.QrCode].includes(col.uidt) && - col?.cdf && + isValidValue(col?.cdf) && !/^\w+\(\)|CURRENT_TIMESTAMP$/.test(col.cdf) ) { const defaultValue = col.cdf