mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-05 05:38:23 +08:00
fix(client): size undefined in nanoid (#3708)
* fix(data-source): foreignkey * fix: size undefined in nanoid
This commit is contained in:
parent
0779a4eab3
commit
e5c1bef8de
@ -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) => {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user