diff --git a/packages/core/client/src/schema-component/antd/nanoIDInput/NanoIDInput.tsx b/packages/core/client/src/schema-component/antd/nanoIDInput/NanoIDInput.tsx index 648cb411e..48deba759 100644 --- a/packages/core/client/src/schema-component/antd/nanoIDInput/NanoIDInput.tsx +++ b/packages/core/client/src/schema-component/antd/nanoIDInput/NanoIDInput.tsx @@ -11,22 +11,22 @@ export const NanoIDInput = Object.assign( connect( AntdInput, mapProps((props: any, field: any) => { - const { size, customAlphabet } = useCollectionField(); + const { size, customAlphabet } = useCollectionField() || {}; const { t } = useTranslation(); const form = useForm(); function isValidNanoid(value) { - if (value.length !== size) { - return t('Field value size is') + ` ${size}`; + if (value?.length !== size) { + return t('Field value size is') + ` ${size || 21}`; } for (let i = 0; i < value.length; i++) { - if (customAlphabet.indexOf(value[i]) === -1) { + if (customAlphabet?.indexOf(value[i]) === -1) { return t(`Field value do not meet the requirements`); } } } useEffect(() => { - if (!field.initialValue) { + if (!field.initialValue && customAlphabet) { field.setInitialValue(Alphabet(customAlphabet, size)()); } form.setFieldState(field.props.name, (state) => { diff --git a/packages/plugins/@nocobase/plugin-data-source-manager/src/client/component/CollectionsManager/components/index.tsx b/packages/plugins/@nocobase/plugin-data-source-manager/src/client/component/CollectionsManager/components/index.tsx index 84ca05760..24a8e578c 100644 --- a/packages/plugins/@nocobase/plugin-data-source-manager/src/client/component/CollectionsManager/components/index.tsx +++ b/packages/plugins/@nocobase/plugin-data-source-manager/src/client/component/CollectionsManager/components/index.tsx @@ -63,7 +63,7 @@ export const ForeignKey = observer( : ['belongsToMany'].includes(type) ? through : target; - const fields = getCollection(effectField || name, dataSourceKey)?.fields; + const fields = getCollection(effectField, dataSourceKey)?.fields; if (fields) { const sourceOptions = fields ?.filter((v) => { @@ -95,7 +95,7 @@ export const ForeignKey = observer( onDropdownVisibleChange={async (open) => { const { target, type, through } = form.values; const effectField = ['belongsTo'].includes(type) - ? collectionName + ? collectionName || name : ['belongsToMany'].includes(type) ? through : target;