mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-02 20:27:49 +08:00
fix(data-template): titleField undefined (#2398)
* fix: titleField undefined * refactor: code improve
This commit is contained in:
parent
a6030a5151
commit
d25b9080b1
@ -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 (
|
||||
<div style={wrapperStyle}>
|
||||
<Space wrap>
|
||||
@ -160,7 +163,7 @@ export const Templates = ({ style = {}, form }) => {
|
||||
value={targetTemplate}
|
||||
onChange={handleTemplateChange}
|
||||
/>
|
||||
{targetTemplate !== 'none' && (
|
||||
{targetTemplate !== 'none' && template && (
|
||||
<RemoteSelect
|
||||
style={{ width: 220 }}
|
||||
fieldNames={{ label: template?.titleField, value: 'id' }}
|
||||
|
Loading…
Reference in New Issue
Block a user