Browse Source

Merge pull request #4026 from nocodb/fix/form-alias

pull/4039/head
Braks 2 years ago committed by GitHub
parent
commit
6867fea72c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      packages/nc-gui/composables/useSharedFormViewStore.ts
  2. 3
      packages/nc-gui/lang/en.json

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

@ -1,5 +1,5 @@
import useVuelidate from '@vuelidate/core' import useVuelidate from '@vuelidate/core'
import { minLength, required } from '@vuelidate/validators' import { helpers, minLength, required } from '@vuelidate/validators'
import type { Ref } from 'vue' import type { Ref } from 'vue'
import type { ColumnType, FormType, LinkToAnotherRecordType, TableType, ViewType } from 'nocodb-sdk' import type { ColumnType, FormType, LinkToAnotherRecordType, TableType, ViewType } from 'nocodb-sdk'
import { ErrorMessages, RelationTypes, UITypes, isVirtualCol } from 'nocodb-sdk' import { ErrorMessages, RelationTypes, UITypes, isVirtualCol } from 'nocodb-sdk'
@ -13,6 +13,7 @@ import {
provide, provide,
ref, ref,
useApi, useApi,
useI18n,
useInjectionState, useInjectionState,
useMetas, useMetas,
useProvideSmartsheetRowStore, useProvideSmartsheetRowStore,
@ -42,6 +43,8 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share
const { metas, setMeta } = useMetas() const { metas, setMeta } = useMetas()
const { t } = useI18n()
const formState = ref({}) const formState = ref({})
const { state: additionalState } = useProvideSmartsheetRowStore( const { state: additionalState } = useProvideSmartsheetRowStore(
@ -53,9 +56,12 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share
}), }),
) )
const fieldRequired = (fieldName = 'Value') => helpers.withMessage(t('msg.error.fieldRequired', { value: fieldName }), required)
const formColumns = computed(() => const formColumns = computed(() =>
columns.value?.filter((c) => c.show).filter((col) => !isVirtualCol(col) || col.uidt === UITypes.LinkToAnotherRecord), columns.value?.filter((c) => c.show).filter((col) => !isVirtualCol(col) || col.uidt === UITypes.LinkToAnotherRecord),
) )
const loadSharedView = async () => { const loadSharedView = async () => {
passwordError.value = null passwordError.value = null
@ -105,7 +111,7 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share
!isVirtualCol(column) && !isVirtualCol(column) &&
((column.rqd && !column.cdf) || (column.pk && !(column.ai || column.cdf)) || column.required) ((column.rqd && !column.cdf) || (column.pk && !(column.ai || column.cdf)) || column.required)
) { ) {
obj.localState[column.title!] = { required } obj.localState[column.title!] = { required: fieldRequired(column.label || column.title) }
} else if ( } else if (
column.uidt === UITypes.LinkToAnotherRecord && column.uidt === UITypes.LinkToAnotherRecord &&
column.colOptions && column.colOptions &&
@ -115,13 +121,13 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share
if ((col && col.rqd && !col.cdf) || column.required) { if ((col && col.rqd && !col.cdf) || column.required) {
if (col) { if (col) {
obj.virtual[column.title!] = { required } obj.virtual[column.title!] = { required: fieldRequired(column.label || column.title) }
} }
} }
} else if (isVirtualCol(column) && column.required) { } else if (isVirtualCol(column) && column.required) {
obj.virtual[column.title!] = { obj.virtual[column.title!] = {
minLength: minLength(1), minLength: minLength(1),
required, required: fieldRequired(column.label || column.title),
} }
} }
} }

3
packages/nc-gui/lang/en.json

@ -651,7 +651,8 @@
"theAcceptedFileTypeIsCsv": "The accepted file type is .csv", "theAcceptedFileTypeIsCsv": "The accepted file type is .csv",
"theAcceptedFileTypesAreXlsXlsxXlsmOdsOts": "The accepted file types are .xls, .xlsx, .xlsm, .ods, .ots", "theAcceptedFileTypesAreXlsXlsxXlsmOdsOts": "The accepted file types are .xls, .xlsx, .xlsm, .ods, .ots",
"parameterKeyCannotBeEmpty": "Parameter key cannot be empty", "parameterKeyCannotBeEmpty": "Parameter key cannot be empty",
"duplicateParameterKeysAreNotAllowed": "Duplicate parameter keys are not allowed" "duplicateParameterKeysAreNotAllowed": "Duplicate parameter keys are not allowed",
"fieldRequired": "{value} cannot be empty."
}, },
"toast": { "toast": {
"exportMetadata": "Project metadata exported successfully", "exportMetadata": "Project metadata exported successfully",

Loading…
Cancel
Save