fix(association-field): default values for the fields of a association field (#2037)

This commit is contained in:
chenos 2023-06-13 09:46:01 +08:00 committed by GitHub
parent 97106c28e8
commit 97a4ef7422
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,10 +39,12 @@ export const AssociationFieldProvider = observer(
if (field.value?.[collectionField.targetKey]) { if (field.value?.[collectionField.targetKey]) {
delete field.value[collectionField.targetKey]; delete field.value[collectionField.targetKey];
} }
field.value = { ...field.initialValue, ...field.value };
} else if (['belongsToMany', 'hasMany'].includes(collectionField.type)) { } else if (['belongsToMany', 'hasMany'].includes(collectionField.type)) {
if (Array.isArray(field.value)) { if (Array.isArray(field.value)) {
field.value.forEach((v) => { field.value = field.value.map((v) => {
delete v[collectionField.targetKey]; delete v[collectionField.targetKey];
return { ...field.initialValue?.[0], ...v };
}); });
} }
} }
@ -65,7 +67,7 @@ export const AssociationFieldProvider = observer(
} }
} }
setLoading(false); setLoading(false);
}, [currentMode, collectionField, field.value]); }, [currentMode, collectionField, JSON.stringify(field.value)]);
if (loading) { if (loading) {
return null; return null;