feat: filter out IDs in sub-forms (#2025)
This commit is contained in:
parent
84e52448f5
commit
8d4123d8d6
@ -33,6 +33,20 @@ export const AssociationFieldProvider = observer(
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
// 如果是表单模板数据,使用子表单和子表格组件时,过滤掉关系 ID
|
||||
if (field.value && field.form['__template'] && ['Nester', 'SubTable'].includes(currentMode)) {
|
||||
if (['belongsTo', 'hasOne'].includes(collectionField.type)) {
|
||||
if (field.value?.[collectionField.targetKey]) {
|
||||
delete field.value[collectionField.targetKey];
|
||||
}
|
||||
} else if (['belongsToMany', 'hasMany'].includes(collectionField.type)) {
|
||||
if (Array.isArray(field.value)) {
|
||||
field.value.forEach((v) => {
|
||||
delete v[collectionField.targetKey];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (field.value !== null && field.value !== undefined) {
|
||||
// Nester 子表单时,如果没数据初始化一个 [null] 的占位
|
||||
if (currentMode === 'Nester' && Array.isArray(field.value)) {
|
||||
|
@ -81,6 +81,7 @@ export const Templates = ({ style = {}, form }) => {
|
||||
|
||||
useEffect(() => {
|
||||
if (enabled && defaultTemplate) {
|
||||
form.__template = true;
|
||||
fetchTemplateData(api, defaultTemplate, t)
|
||||
.then((data) => {
|
||||
if (form && data) {
|
||||
@ -106,6 +107,7 @@ export const Templates = ({ style = {}, form }) => {
|
||||
if (form && data) {
|
||||
// 切换之前先把之前的数据清空
|
||||
form.reset();
|
||||
form.__template = true;
|
||||
|
||||
forEach(data, (value, key) => {
|
||||
if (value) {
|
||||
|
Loading…
Reference in New Issue
Block a user