Browse Source

fix(gui-v2): if json parsing failed set attachments as an empty array

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/3188/head
Pranav C 2 years ago
parent
commit
304d91875f
  1. 6
      packages/nc-gui-v2/components/cell/attachment/index.vue
  2. 2
      packages/nc-gui-v2/composables/useSharedFormViewStore.ts

6
packages/nc-gui-v2/components/cell/attachment/index.vue

@ -59,7 +59,11 @@ watch(
() => modelValue,
(nextModel) => {
if (nextModel) {
attachments.value = ((typeof nextModel === 'string' ? JSON.parse(nextModel) : nextModel) || []).filter(Boolean)
try {
attachments.value = ((typeof nextModel === 'string' ? JSON.parse(nextModel) : nextModel) || []).filter(Boolean)
} catch {
attachments.value = []
}
}
},
{ immediate: true },

2
packages/nc-gui-v2/composables/useSharedFormViewStore.ts

@ -116,7 +116,7 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share
const data: Record<string, any> = { ...(formState?.value ?? {}), ...(additionalState?.value || {}) }
const attachment: Record<string, any> = {}
for (const col of metas?.value?.[sharedFormView?.value?.fk_model_id as string]?.columns ?? []) {
for (const col of metas?.value?.[sharedView?.value?.fk_model_id as string]?.columns ?? []) {
if (col.uidt === UITypes.Attachment) {
attachment[`_${col.title}`] = data[col.title!]
delete data[col.title!]

Loading…
Cancel
Save