fix: useCreateActionProps & useUpdateActionProps

This commit is contained in:
chenos 2022-04-18 20:04:28 +08:00
parent da9e08a59f
commit 0c2b9741ed

View File

@ -49,11 +49,17 @@ export const useCreateActionProps = () => {
if (fieldNames.includes(key)) { if (fieldNames.includes(key)) {
const items = form.values[key]; const items = form.values[key];
const collectionField = getField(key); const collectionField = getField(key);
const targetKey = collectionField.targetKey || 'id'; if (collectionField.interface === 'linkTo') {
if (Array.isArray(items)) { const targetKey = collectionField.targetKey || 'id';
values[key] = items.map((item) => item[targetKey]); if (Array.isArray(items)) {
} else if (items && typeof items === 'object') { values[key] = items.map((item) => item[targetKey]);
values[key] = items[targetKey]; } else if (items && typeof items === 'object') {
values[key] = items[targetKey];
} else {
values[key] = items[targetKey];
}
} else {
values[key] = form.values[key];
} }
} else { } else {
values[key] = form.values[key]; values[key] = form.values[key];
@ -118,6 +124,8 @@ export const useUpdateActionProps = () => {
values[key] = items.map((item) => item[targetKey]); values[key] = items.map((item) => item[targetKey]);
} else if (items && typeof items === 'object') { } else if (items && typeof items === 'object') {
values[key] = items[targetKey]; values[key] = items[targetKey];
} else {
values[key] = items[targetKey];
} }
} else { } else {
values[key] = form.values[key]; values[key] = form.values[key];