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(
|
connect(
|
||||||
AntdInput,
|
AntdInput,
|
||||||
mapProps((props: any, field: any) => {
|
mapProps((props: any, field: any) => {
|
||||||
const { size, customAlphabet } = useCollectionField();
|
const { size, customAlphabet } = useCollectionField() || {};
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const form = useForm();
|
const form = useForm();
|
||||||
function isValidNanoid(value) {
|
function isValidNanoid(value) {
|
||||||
if (value.length !== size) {
|
if (value?.length !== size) {
|
||||||
return t('Field value size is') + ` ${size}`;
|
return t('Field value size is') + ` ${size || 21}`;
|
||||||
}
|
}
|
||||||
for (let i = 0; i < value.length; i++) {
|
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`);
|
return t(`Field value do not meet the requirements`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!field.initialValue) {
|
if (!field.initialValue && customAlphabet) {
|
||||||
field.setInitialValue(Alphabet(customAlphabet, size)());
|
field.setInitialValue(Alphabet(customAlphabet, size)());
|
||||||
}
|
}
|
||||||
form.setFieldState(field.props.name, (state) => {
|
form.setFieldState(field.props.name, (state) => {
|
||||||
|
@ -63,7 +63,7 @@ export const ForeignKey = observer(
|
|||||||
: ['belongsToMany'].includes(type)
|
: ['belongsToMany'].includes(type)
|
||||||
? through
|
? through
|
||||||
: target;
|
: target;
|
||||||
const fields = getCollection(effectField || name, dataSourceKey)?.fields;
|
const fields = getCollection(effectField, dataSourceKey)?.fields;
|
||||||
if (fields) {
|
if (fields) {
|
||||||
const sourceOptions = fields
|
const sourceOptions = fields
|
||||||
?.filter((v) => {
|
?.filter((v) => {
|
||||||
@ -95,7 +95,7 @@ export const ForeignKey = observer(
|
|||||||
onDropdownVisibleChange={async (open) => {
|
onDropdownVisibleChange={async (open) => {
|
||||||
const { target, type, through } = form.values;
|
const { target, type, through } = form.values;
|
||||||
const effectField = ['belongsTo'].includes(type)
|
const effectField = ['belongsTo'].includes(type)
|
||||||
? collectionName
|
? collectionName || name
|
||||||
: ['belongsToMany'].includes(type)
|
: ['belongsToMany'].includes(type)
|
||||||
? through
|
? through
|
||||||
: target;
|
: target;
|
||||||
|
Loading…
Reference in New Issue
Block a user