From 6abe97291ebc06da401d48ef80bdaccfc907bc04 Mon Sep 17 00:00:00 2001
From: Rairn <958414905@qq.com>
Date: Sun, 16 Apr 2023 17:24:43 +0800
Subject: [PATCH] fix(data-templates): fix subform
---
.../src/block-provider/FormFieldProvider.tsx | 25 ++++++++++++-------
.../antd/form-v2/FormField.tsx | 4 +--
2 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/packages/core/client/src/block-provider/FormFieldProvider.tsx b/packages/core/client/src/block-provider/FormFieldProvider.tsx
index bdb1fec57..989363513 100644
--- a/packages/core/client/src/block-provider/FormFieldProvider.tsx
+++ b/packages/core/client/src/block-provider/FormFieldProvider.tsx
@@ -1,6 +1,6 @@
-import { createForm, onFieldReact, onFormInputChange, onFormValuesChange } from '@formily/core';
-import { ArrayField, Field, ObjectField } from '@formily/core';
-import { useField, useFieldSchema } from '@formily/react';
+import { createForm, onFormValuesChange } from '@formily/core';
+import { useField } from '@formily/react';
+import { autorun } from '@formily/reactive';
import { Spin } from 'antd';
import React, { createContext, useContext, useEffect, useMemo } from 'react';
import { RecordProvider } from '../record-provider';
@@ -32,6 +32,15 @@ const InternalFormFieldProvider = (props) => {
[],
);
+ // 当使用数据模板时,会 formBlockCtx.form.values 会被整体赋值,这时候需要同步到 form.values
+ useEffect(() => {
+ const dispose = autorun(() => {
+ form.values = formBlockCtx?.form?.values[fieldName] || form.values;
+ });
+
+ return dispose;
+ }, []);
+
const { resource, service } = useBlockRequestContext();
if (service.loading) {
return