fix(data-template): fix title input prevented proper data switching (#1937)

* fix(data-template): fix title input prevented proper data switching

* fix: build error

* fix: clear the previous data before switching
This commit is contained in:
被雨水过滤的空气-Rairn 2023-05-26 12:08:26 +08:00 committed by GitHub
parent 644b6eccb3
commit fa778b31af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -100,6 +100,9 @@ export const Templates = ({ style = {}, form }) => {
fetchTemplateData(api, option, t)
.then((data) => {
if (form && data) {
// 切换之前先把之前的数据清空
form.reset();
forEach(data, (value, key) => {
if (value) {
form.values[key] = value;

View File

@ -9,7 +9,7 @@ import { clone } from 'lodash';
import React, { Fragment, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
const DataTemplateTitle = (props) => {
const DataTemplateTitle = observer<{ index: number; item: any }>((props) => {
const array = ArrayBase.useArray();
const index = ArrayBase.useIndex(props.index);
const { t } = useTranslation();
@ -22,17 +22,18 @@ const DataTemplateTitle = (props) => {
value.title = `${t('Template name')} ${array?.field?.value?.length}`;
}
}, []);
return (
<Input.TextArea
value={value.title}
placeholder={t('Template name')}
onChange={(ev) => {
ev.stopPropagation();
array.field.value.splice(index, 1, { ...value, title: ev.target.value });
value.title = ev.target.value;
}}
onBlur={(ev) => {
ev.stopPropagation();
array.field.value.splice(index, 1, { ...value, title: ev.target.value });
value.title = ev.target.value;
}}
autoSize
style={{ width: '70%', border: 'none' }}
@ -41,7 +42,7 @@ const DataTemplateTitle = (props) => {
}}
/>
);
};
});
export interface IArrayCollapseProps extends CollapseProps {
defaultOpenPanelCount?: number;