diff --git a/packages/nc-gui/composables/useSharedFormViewStore.ts b/packages/nc-gui/composables/useSharedFormViewStore.ts index a425bb3fe2..c790c9451c 100644 --- a/packages/nc-gui/composables/useSharedFormViewStore.ts +++ b/packages/nc-gui/composables/useSharedFormViewStore.ts @@ -12,6 +12,7 @@ import type { } from 'nocodb-sdk' import { ErrorMessages, RelationTypes, UITypes, isLinksOrLTAR, isVirtualCol } from 'nocodb-sdk' import { isString } from '@vue/shared' +import { filterNullOrUndefinedObjectProperties } from '~/helpers/parsers/parserHelpers' import { SharedViewPasswordInj, computed, @@ -198,18 +199,16 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share } } - await api.public.dataCreate( - sharedView.value!.uuid!, - { - data, - ...attachment, - }, - { - headers: { - 'xc-password': password.value, - }, + const filtedData = filterNullOrUndefinedObjectProperties({ + data, + ...attachment, + }) + + await api.public.dataCreate(sharedView.value!.uuid!, filtedData, { + headers: { + 'xc-password': password.value, }, - ) + }) submitted.value = true progress.value = false diff --git a/packages/nc-gui/helpers/parsers/parserHelpers.ts b/packages/nc-gui/helpers/parsers/parserHelpers.ts index 16321fe2bd..a54a10759e 100644 --- a/packages/nc-gui/helpers/parsers/parserHelpers.ts +++ b/packages/nc-gui/helpers/parsers/parserHelpers.ts @@ -174,3 +174,20 @@ export const getColumnUIDTAndMetas = (colData: [], defaultType: string) => { // TODO(import): date / datetime return colProps } + +export const filterNullOrUndefinedObjectProperties = >(obj: T): T => { + return Object.keys(obj).reduce((result, propName) => { + const value = obj[propName] + + if (value !== null && value !== undefined) { + if (!Array.isArray(value) && typeof value === 'object') { + // Recursively filter nested objects + result[propName] = filterNullOrUndefinedObjectProperties(value) + } else { + result[propName] = value + } + } + + return result + }, {} as Record) as T +}