Skip to content

Commit 9d2be09

Browse files
committed
fix: 🐛 (shadow-form) form -> subFormOptions, and inherit parent
1 parent 42339a0 commit 9d2be09

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/pro-array-table/mixin.pro.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export const ArrayTableShowModal: React.FC<
146146
CommonShadowPopup
147147
> = (props) => {
148148
const { SchemaField, form, schema } = useShadowForm(
149-
pick(props, "schema", "schemaFieldOptions", "form"),
149+
pick(props, "schema", "schemaFieldOptions", "subFormOptions"),
150150
);
151151
const mySchema = useFieldSchema();
152152
const act = props.act ?? mySchema.name;
@@ -189,7 +189,7 @@ export const ArrayTableShowModal: React.FC<
189189

190190
return (
191191
<Modal
192-
{...omit(props, "act", "schema", "schemaFieldOptions", "form")}
192+
{...omit(props, "act", "schema", "schemaFieldOptions", "subFormOptions")}
193193
open={visible}
194194
title={field.title}
195195
onCancel={() => {

src/shadow-form/shadow-form.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
SchemaOptionsContext,
77
createSchemaField,
88
useField,
9+
useForm,
910
} from "@formily/react";
1011
import React, { useContext, useMemo } from "react";
1112
import ReactIs from "react-is";
@@ -32,13 +33,18 @@ export interface IShadowFormOptions {
3233
/** createSchemaField 函数配置, components 和 scope */
3334
schemaFieldOptions?: Parameters<typeof useShadowSchemaField>[0];
3435
/** createForm 创建的表单实例, 有自定义 effects 等可以通过自定义一个 form 这个传入 */
35-
form?: ReturnType<typeof createForm>;
36+
subFormOptions?: Parameters<typeof createForm>[0];
3637
}
3738

3839
export const useShadowForm = (options: IShadowFormOptions) => {
39-
const { schema, schemaFieldOptions, form } = options;
40+
const { schema, schemaFieldOptions, subFormOptions } = options;
41+
const form = useForm();
4042
const SchemaField = useShadowSchemaField(schemaFieldOptions);
41-
const realForm = useMemo(() => form ?? createForm({}), [form]);
43+
44+
const realForm = useMemo(
45+
() => createForm({ ...form.props, ...subFormOptions }),
46+
[subFormOptions, form.props],
47+
);
4248
return {
4349
form: realForm,
4450
schema,

0 commit comments

Comments
 (0)