Merge branch 'main' into next
Some checks are pending
Build Docker Image / build-and-push (push) Waiting to run
Build Pro Image / build-and-push (push) Waiting to run
E2E / Build (push) Waiting to run
E2E / Core and plugins (push) Blocked by required conditions
E2E / plugin-workflow (push) Blocked by required conditions
E2E / plugin-workflow-approval (push) Blocked by required conditions
E2E / plugin-data-source-main (push) Blocked by required conditions
E2E / Comment on PR (push) Blocked by required conditions
NocoBase FrontEnd Test / frontend-test (18) (push) Waiting to run

This commit is contained in:
Zeke Zhang 2024-07-13 19:20:20 +08:00
commit 7ee6eac0f7
2 changed files with 9 additions and 3 deletions

View File

@ -7,7 +7,7 @@
* For more information, please refer to: https://www.nocobase.com/agreement. * For more information, please refer to: https://www.nocobase.com/agreement.
*/ */
import { createForm } from '@formily/core'; import { createForm, Form } from '@formily/core';
import { Schema, useField } from '@formily/react'; import { Schema, useField } from '@formily/react';
import { Spin } from 'antd'; import { Spin } from 'antd';
import React, { createContext, useContext, useEffect, useMemo, useRef } from 'react'; import React, { createContext, useContext, useEffect, useMemo, useRef } from 'react';
@ -165,7 +165,13 @@ export const useFormBlockProps = () => {
useEffect(() => { useEffect(() => {
if (!ctx?.service?.loading) { if (!ctx?.service?.loading) {
ctx.form?.setInitialValues(ctx.service?.data?.data); const form: Form = ctx.form;
if (form) {
// form 字段中可能一开始就存在一些默认值(比如设置了字段默认值的模板区块)。在编辑表单中,
// 这些默认值是不需要的需要清除掉不然会导致一些问题。比如https://github.com/nocobase/nocobase/issues/4868
form.initialValues = {};
form.setInitialValues(ctx.service?.data?.data);
}
} }
}, [ctx?.service?.loading]); }, [ctx?.service?.loading]);
return { return {

View File

@ -55,7 +55,7 @@ const InternalAssociationSelect = observer(
const { objectValue = true, addMode: propsAddMode, ...rest } = props; const { objectValue = true, addMode: propsAddMode, ...rest } = props;
const field: any = useField(); const field: any = useField();
const fieldSchema = useFieldSchema(); const fieldSchema = useFieldSchema();
const service = useServiceOptions(props); const service = useServiceOptions(fieldSchema?.['x-component-props'] || props);
const { options: collectionField } = useAssociationFieldContext(); const { options: collectionField } = useAssociationFieldContext();
const initValue = isVariable(props.value) ? undefined : props.value; const initValue = isVariable(props.value) ? undefined : props.value;
const value = Array.isArray(initValue) ? initValue.filter(Boolean) : initValue; const value = Array.isArray(initValue) ? initValue.filter(Boolean) : initValue;