From 808d7ca5c37b146e0086f55551c214ae6f72e23a Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Wed, 12 Oct 2022 11:07:47 +0200 Subject: [PATCH] fix(nc-gui): use column label or title for error msg in form view --- .../nc-gui/composables/useSharedFormViewStore.ts | 14 ++++++++++---- packages/nc-gui/lang/en.json | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/nc-gui/composables/useSharedFormViewStore.ts b/packages/nc-gui/composables/useSharedFormViewStore.ts index 32052079d1..b3f7531820 100644 --- a/packages/nc-gui/composables/useSharedFormViewStore.ts +++ b/packages/nc-gui/composables/useSharedFormViewStore.ts @@ -1,5 +1,5 @@ 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 { ColumnType, FormType, LinkToAnotherRecordType, TableType, ViewType } from 'nocodb-sdk' import { ErrorMessages, RelationTypes, UITypes, isVirtualCol } from 'nocodb-sdk' @@ -13,6 +13,7 @@ import { provide, ref, useApi, + useI18n, useInjectionState, useMetas, useProvideSmartsheetRowStore, @@ -42,6 +43,8 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share const { metas, setMeta } = useMetas() + const { t } = useI18n() + const formState = ref({}) 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(() => columns.value?.filter((c) => c.show).filter((col) => !isVirtualCol(col) || col.uidt === UITypes.LinkToAnotherRecord), ) + const loadSharedView = async () => { passwordError.value = null @@ -105,7 +111,7 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share !isVirtualCol(column) && ((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 ( column.uidt === UITypes.LinkToAnotherRecord && column.colOptions && @@ -115,13 +121,13 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share if ((col && col.rqd && !col.cdf) || column.required) { if (col) { - obj.virtual[column.title!] = { required } + obj.virtual[column.title!] = { required: fieldRequired(column.label || column.title) } } } } else if (isVirtualCol(column) && column.required) { obj.virtual[column.title!] = { minLength: minLength(1), - required, + required: fieldRequired(column.label || column.title), } } } diff --git a/packages/nc-gui/lang/en.json b/packages/nc-gui/lang/en.json index 42947645d2..c3fa9c9a75 100644 --- a/packages/nc-gui/lang/en.json +++ b/packages/nc-gui/lang/en.json @@ -651,7 +651,8 @@ "theAcceptedFileTypeIsCsv": "The accepted file type is .csv", "theAcceptedFileTypesAreXlsXlsxXlsmOdsOts": "The accepted file types are .xls, .xlsx, .xlsm, .ods, .ots", "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": { "exportMetadata": "Project metadata exported successfully",