fix(defaultValue): avoid directly displaying variable strings (#6649)

This commit is contained in:
Zeke Zhang 2025-04-13 14:03:51 +08:00 committed by GitHub
parent d69fbfeb1b
commit 4bc16e52f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 6 deletions

View File

@ -18,6 +18,7 @@ import { useCollectionFieldUISchema, useIsInNocoBaseRecursionFieldContext } from
import { useDynamicComponentProps } from '../../hoc/withDynamicSchemaProps';
import { useCompile, useComponent } from '../../schema-component';
import { useIsAllowToSetDefaultValue } from '../../schema-settings/hooks/useIsAllowToSetDefaultValue';
import { isVariable } from '../../variables/utils/isVariable';
import { CollectionFieldProvider, useCollectionField } from './CollectionFieldProvider';
type Props = {
@ -131,7 +132,14 @@ const CollectionFieldInternalField = (props) => {
if (!uiSchema) return null;
return <Component {...props} {...dynamicProps} />;
const mergedProps = { ...props, ...dynamicProps };
// Prevent displaying the variable string first, then the variable value
if (isVariable(mergedProps.value) && mergedProps.value === fieldSchema.default) {
mergedProps.value = undefined;
}
return <Component {...mergedProps} />;
};
export const CollectionField = connect((props) => {

View File

@ -86,11 +86,6 @@ const useParseDefaultValue = () => {
field &&
((isVariable(fieldSchema.default) && field.value == null) || field.value === fieldSchema.default || forceUpdate)
) {
// 一个变量字符串如果显示出来会比较奇怪
if (isVariable(field.value)) {
await field.reset({ forceClear: true });
}
field.loading = true;
const collectionField = !fieldSchema.name.toString().includes('.') && collection?.getField(fieldSchema.name);