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)) {
const items = form.values[key];
const collectionField = getField(key);
const targetKey = collectionField.targetKey || 'id';
if (Array.isArray(items)) {
values[key] = items.map((item) => item[targetKey]);
} else if (items && typeof items === 'object') {
values[key] = items[targetKey];
if (collectionField.interface === 'linkTo') {
const targetKey = collectionField.targetKey || 'id';
if (Array.isArray(items)) {
values[key] = items.map((item) => item[targetKey]);
} else if (items && typeof items === 'object') {
values[key] = items[targetKey];
} else {
values[key] = items[targetKey];
}
} else {
values[key] = form.values[key];
}
} else {
values[key] = form.values[key];
@ -118,6 +124,8 @@ export const useUpdateActionProps = () => {
values[key] = items.map((item) => item[targetKey]);
} else if (items && typeof items === 'object') {
values[key] = items[targetKey];
} else {
values[key] = items[targetKey];
}
} else {
values[key] = form.values[key];