Browse Source

Nc fix(nc-gui): Hide pre-filled fields form submit issue (#9182)

* fix(nc-gui): prefilled hidden field form submit issue

* fix(nc-gui): filter undefined validation fields

* fix(nc-gui): use optional chaining while accessing nested object

* fix(nc-gui): pr review changes

* chore(nc-gui): lint
pull/9183/head
Ramesh Mane 4 months ago committed by GitHub
parent
commit
3315369278
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 14
      packages/nc-gui/components/smartsheet/Form.vue
  2. 5
      packages/nc-gui/composables/useFormViewStore.ts
  3. 19
      packages/nc-gui/composables/useSharedFormViewStore.ts
  4. 17
      packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue
  5. 5
      packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue

14
packages/nc-gui/components/smartsheet/Form.vue

@ -199,8 +199,14 @@ async function submitForm() {
} }
try { 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) { } catch (e: any) {
console.error(e)
if (e?.errorFields?.length) { if (e?.errorFields?.length) {
message.error(t('msg.error.someOfTheRequiredFieldsAreEmpty')) message.error(t('msg.error.someOfTheRequiredFieldsAreEmpty'))
return return
@ -587,7 +593,11 @@ watch(
updatePreFillFormSearchParams() updatePreFillFormSearchParams()
try { 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 {} } catch {}
}, },
{ {

5
packages/nc-gui/composables/useFormViewStore.ts

@ -104,6 +104,11 @@ const [useProvideFormViewStore, useFormViewStore] = useInjectionState(
const validateActiveField = async (col: ColumnType) => { const validateActiveField = async (col: ColumnType) => {
if (!col.title) return if (!col.title) return
if (fieldMappings.value[col.title] === undefined) {
console.warn('Missing mapping field for:', col.title)
return
}
try { try {
await validate(fieldMappings.value[col.title]) await validate(fieldMappings.value[col.title])
} catch {} } catch {}

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

@ -279,13 +279,18 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share
handleAddMissingRequiredFieldDefaultState() handleAddMissingRequiredFieldDefaultState()
try { try {
await validate([ // filter `undefined` keys which is hidden prefilled fields
await validate(
[
...Object.keys(formState.value).map((title) => fieldMappings.value[title]), ...Object.keys(formState.value).map((title) => fieldMappings.value[title]),
...Object.keys(additionalState.value).map((title) => fieldMappings.value[title]), ...Object.keys(additionalState.value).map((title) => fieldMappings.value[title]),
]) ].filter((v) => v !== undefined),
)
return true return true
} catch (e: any) { } 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')) message.error(t('msg.error.someOfTheRequiredFieldsAreEmpty'))
return false return false
} }
@ -325,7 +330,7 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share
submitted.value = true submitted.value = true
progress.value = false progress.value = false
} catch (e: any) { } catch (e: any) {
console.log(e) console.error(e)
await message.error(await extractSdkResponseErrorMsg(e)) await message.error(await extractSdkResponseErrorMsg(e))
} }
progress.value = false progress.value = false
@ -643,7 +648,11 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share
additionalState, additionalState,
async () => { async () => {
try { 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 {} } catch {}
}, },
{ {

17
packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue

@ -79,6 +79,21 @@ const onDecode = async (scannedCodeValue: string) => {
console.error(error) 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
}
}
</script> </script>
<template> <template>
@ -232,7 +247,7 @@ const onDecode = async (scannedCodeValue: string) => {
:read-only="field?.read_only" :read-only="field?.read_only"
@update:model-value=" @update:model-value="
() => { () => {
validate(fieldMappings[field.title]) validateField(field.title)
} }
" "
/> />

5
packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue

@ -111,6 +111,11 @@ function animate(target: AnimationTarget) {
} }
const validateField = async (title: string) => { const validateField = async (title: string) => {
if (fieldMappings.value[title] === undefined) {
console.warn('Missing mapping field for:', title)
return false
}
try { try {
await validate(fieldMappings.value[title]) await validate(fieldMappings.value[title])

Loading…
Cancel
Save