mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 10:37:01 +00:00
fix: fix default value is invalid in subform (#1989)
* fix: fix default value is invalid in subform * perf: use useMemo * fix: change null to {}
This commit is contained in:
parent
d7e6b7b320
commit
b33c00be8f
@ -36,7 +36,7 @@ export const AssociationFieldProvider = observer((props) => {
|
||||
// Nester 子表单时,如果没数据初始化一个 [null] 的占位
|
||||
if (currentMode === 'Nester' && Array.isArray(field.value)) {
|
||||
if (field.value.length === 0 && ['belongsToMany', 'hasMany'].includes(collectionField.type)) {
|
||||
field.value = [null];
|
||||
field.value = [{}];
|
||||
}
|
||||
}
|
||||
setLoading(false);
|
||||
@ -46,7 +46,7 @@ export const AssociationFieldProvider = observer((props) => {
|
||||
if (['belongsTo', 'hasOne'].includes(collectionField.type)) {
|
||||
field.value = {};
|
||||
} else if (['belongsToMany', 'hasMany'].includes(collectionField.type)) {
|
||||
field.value = [null];
|
||||
field.value = [{}];
|
||||
}
|
||||
}
|
||||
setLoading(false);
|
||||
|
@ -60,7 +60,7 @@ const ToManyNester = observer((props) => {
|
||||
startIndex: index + 1,
|
||||
insertCount: 1,
|
||||
});
|
||||
field.value.splice(index + 1, 0, null);
|
||||
field.value.splice(index + 1, 0, {});
|
||||
return field.onInput(field.value);
|
||||
});
|
||||
}}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import flat from 'flat';
|
||||
import _, { every, findIndex, some, isArray } from 'lodash';
|
||||
import _, { every, findIndex, isArray, some } from 'lodash';
|
||||
import moment from 'moment';
|
||||
import { useMemo } from 'react';
|
||||
import { useCurrentUserContext } from '../../../user';
|
||||
import jsonLogic from '../../common/utils/logic';
|
||||
|
||||
@ -13,12 +14,14 @@ type VariablesCtx = {
|
||||
export const useVariablesCtx = (): VariablesCtx => {
|
||||
const { data } = useCurrentUserContext() || {};
|
||||
|
||||
return {
|
||||
$user: data?.data || {},
|
||||
$date: {
|
||||
now: () => moment().toISOString(),
|
||||
},
|
||||
};
|
||||
return useMemo(() => {
|
||||
return {
|
||||
$user: data?.data || {},
|
||||
$date: {
|
||||
now: () => moment().toISOString(),
|
||||
},
|
||||
};
|
||||
}, [data]);
|
||||
};
|
||||
|
||||
export const isVariable = (str: unknown) => {
|
||||
@ -63,7 +66,7 @@ const getFieldValue = (fieldPath, values) => {
|
||||
const regex = new RegExp('^' + v + '\\..+\\.' + h + '$'); // 构建匹配的正则表达式
|
||||
const matchedValues = [];
|
||||
const data = flat.flatten(values, { maxDepth: 3 });
|
||||
for (var key in data) {
|
||||
for (const key in data) {
|
||||
if (regex.test(key)) {
|
||||
matchedValues.push(data[key]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user