From d25b9080b1da00a9f0fd8770a1a9e463263e7467 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Tue, 8 Aug 2023 17:21:09 +0800 Subject: [PATCH] fix(data-template): titleField undefined (#2398) * fix: titleField undefined * refactor: code improve --- .../src/schema-component/antd/form-v2/Templates.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/form-v2/Templates.tsx b/packages/core/client/src/schema-component/antd/form-v2/Templates.tsx index 2324ca9a8..73e14b2e9 100644 --- a/packages/core/client/src/schema-component/antd/form-v2/Templates.tsx +++ b/packages/core/client/src/schema-component/antd/form-v2/Templates.tsx @@ -101,7 +101,11 @@ export const Templates = ({ style = {}, form }) => { } } }, []); - + useEffect(() => { + if (!templateOptions?.some((v) => v.key === targetTemplate)) { + handleTemplateChange('none'); + } + }, [templateOptions]); const wrapperStyle = useMemo(() => { return { display: 'flex', alignItems: 'center', backgroundColor: token.colorFillAlter, padding: '1em', ...style }; }, [style, token.colorFillAlter]); @@ -115,7 +119,7 @@ export const Templates = ({ style = {}, form }) => { return { fontSize: token.fontSize, fontWeight: 'bold', whiteSpace: 'nowrap', marginRight: token.marginXS }; }, [token.fontSize, token.marginXS]); - const handleTemplateChange = useCallback(async (value, option) => { + const handleTemplateChange = useCallback(async (value) => { setTargetTemplate(value); setTemplateData(null); form?.reset(); @@ -148,7 +152,6 @@ export const Templates = ({ style = {}, form }) => { return null; } const template = templateOptions?.find((v) => v.key === targetTemplate); - return (
@@ -160,7 +163,7 @@ export const Templates = ({ style = {}, form }) => { value={targetTemplate} onChange={handleTemplateChange} /> - {targetTemplate !== 'none' && ( + {targetTemplate !== 'none' && template && (