Browse Source

🐛 Bug: default value not applied if value was modified before submitting link shared form

Co-authored-by: gitstart <gitstart@gitstart.com>
Co-authored-by: sheldon-welinga <sheldonwelinga@gmail.com>
Co-authored-by: gitstart_bot <gitstart_bot@users.noreply.github.com>
pull/6472/head
gitstart 1 year ago
parent
commit
9c519987b1
  1. 13
      packages/nc-gui/composables/useSharedFormViewStore.ts
  2. 17
      packages/nc-gui/helpers/parsers/parserHelpers.ts

13
packages/nc-gui/composables/useSharedFormViewStore.ts

@ -12,6 +12,7 @@ import type {
} from 'nocodb-sdk' } from 'nocodb-sdk'
import { ErrorMessages, RelationTypes, UITypes, isLinksOrLTAR, isVirtualCol } from 'nocodb-sdk' import { ErrorMessages, RelationTypes, UITypes, isLinksOrLTAR, isVirtualCol } from 'nocodb-sdk'
import { isString } from '@vue/shared' import { isString } from '@vue/shared'
import { filterNullOrUndefinedObjectProperties } from '~/helpers/parsers/parserHelpers'
import { import {
SharedViewPasswordInj, SharedViewPasswordInj,
computed, computed,
@ -198,18 +199,16 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share
} }
} }
await api.public.dataCreate( const filtedData = filterNullOrUndefinedObjectProperties({
sharedView.value!.uuid!,
{
data, data,
...attachment, ...attachment,
}, })
{
await api.public.dataCreate(sharedView.value!.uuid!, filtedData, {
headers: { headers: {
'xc-password': password.value, 'xc-password': password.value,
}, },
}, })
)
submitted.value = true submitted.value = true
progress.value = false progress.value = false

17
packages/nc-gui/helpers/parsers/parserHelpers.ts

@ -175,3 +175,20 @@ export const getColumnUIDTAndMetas = (colData: [], defaultType: string) => {
// TODO(import): date / datetime // TODO(import): date / datetime
return colProps return colProps
} }
export const filterNullOrUndefinedObjectProperties = <T extends Record<string, any>>(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<string, any>) as T
}

Loading…
Cancel
Save