fix(form): resolve issue with association fields not displaying content due to referenced templates (#4876)

This commit is contained in:
Zeke Zhang 2024-07-13 19:18:27 +08:00 committed by GitHub
parent 96e7145da5
commit 1fb065a99b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,7 +7,7 @@
* 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 { Spin } from 'antd';
import React, { createContext, useContext, useEffect, useMemo, useRef } from 'react';
@ -167,7 +167,13 @@ export const useFormBlockProps = () => {
useEffect(() => {
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]);
return {