diff --git a/packages/nc-gui/components/smartsheet/Form.vue b/packages/nc-gui/components/smartsheet/Form.vue index a3e83848da..1e6c67e631 100644 --- a/packages/nc-gui/components/smartsheet/Form.vue +++ b/packages/nc-gui/components/smartsheet/Form.vue @@ -199,8 +199,14 @@ async function submitForm() { } try { - await validate(Object.keys(formState.value).map((title) => fieldMappings.value[title])) + await validate( + Object.keys(formState.value) + .map((title) => fieldMappings.value[title]) + .filter((v) => v !== undefined), + ) } catch (e: any) { + console.error(e) + if (e?.errorFields?.length) { message.error(t('msg.error.someOfTheRequiredFieldsAreEmpty')) return @@ -587,7 +593,11 @@ watch( updatePreFillFormSearchParams() try { - await validate(Object.keys(formState.value).map((title) => fieldMappings.value[title])) + await validate( + Object.keys(formState.value) + .map((title) => fieldMappings.value[title]) + .filter((v) => v !== undefined), + ) } catch {} }, { diff --git a/packages/nc-gui/composables/useFormViewStore.ts b/packages/nc-gui/composables/useFormViewStore.ts index a9d66ca981..73b30ce0c9 100644 --- a/packages/nc-gui/composables/useFormViewStore.ts +++ b/packages/nc-gui/composables/useFormViewStore.ts @@ -104,6 +104,11 @@ const [useProvideFormViewStore, useFormViewStore] = useInjectionState( const validateActiveField = async (col: ColumnType) => { if (!col.title) return + if (fieldMappings.value[col.title] === undefined) { + console.warn('Missing mapping field for:', col.title) + return + } + try { await validate(fieldMappings.value[col.title]) } catch {} diff --git a/packages/nc-gui/composables/useSharedFormViewStore.ts b/packages/nc-gui/composables/useSharedFormViewStore.ts index 4f30313971..846fffb2c1 100644 --- a/packages/nc-gui/composables/useSharedFormViewStore.ts +++ b/packages/nc-gui/composables/useSharedFormViewStore.ts @@ -279,13 +279,18 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share handleAddMissingRequiredFieldDefaultState() try { - await validate([ - ...Object.keys(formState.value).map((title) => fieldMappings.value[title]), - ...Object.keys(additionalState.value).map((title) => fieldMappings.value[title]), - ]) + // filter `undefined` keys which is hidden prefilled fields + await validate( + [ + ...Object.keys(formState.value).map((title) => fieldMappings.value[title]), + ...Object.keys(additionalState.value).map((title) => fieldMappings.value[title]), + ].filter((v) => v !== undefined), + ) return true } catch (e: any) { - if (e.errorFields.length) { + console.error('Error occurred while validating all fields:', e) + + if (e?.errorFields?.length) { message.error(t('msg.error.someOfTheRequiredFieldsAreEmpty')) return false } @@ -325,7 +330,7 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share submitted.value = true progress.value = false } catch (e: any) { - console.log(e) + console.error(e) await message.error(await extractSdkResponseErrorMsg(e)) } progress.value = false @@ -643,7 +648,11 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share additionalState, async () => { try { - await validate(Object.keys(additionalState.value).map((title) => fieldMappings.value[title])) + await validate( + Object.keys(additionalState.value) + .map((title) => fieldMappings.value[title]) + .filter((v) => v !== undefined), + ) } catch {} }, { diff --git a/packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue b/packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue index a09cf6c100..bc4840f8d8 100644 --- a/packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue +++ b/packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue @@ -79,6 +79,21 @@ const onDecode = async (scannedCodeValue: string) => { console.error(error) } } + +const validateField = async (title: string) => { + if (fieldMappings.value[title] === undefined) { + console.warn('Missing mapping field for:', title) + return false + } + + try { + await validate(fieldMappings.value[title]) + + return true + } catch (_e: any) { + return false + } +}