rising-crimson
rising-crimson16mo ago

How can I send an attribute other than data to the request in "onFinish"?(ant.design, strapi v4)

I want to upload file(strapi v4 mediatype). Strapi V4 Example
//https://docs.strapi.io/developer-docs/latest/plugins/upload.html#examples

const formData = new FormData();

formData.append('data', JSON.stringify(data));
formData.append('files.entryName', file);
//https://docs.strapi.io/developer-docs/latest/plugins/upload.html#examples

const formData = new FormData();

formData.append('data', JSON.stringify(data));
formData.append('files.entryName', file);
Refine(Ant Design) Example
onFinish({
attribute1: "..."
attribute2: "..."
file.entryName: FileObj
})


// https://refine.dev/docs/api-reference/antd/hooks/form/useForm/#how-can-i-change-the-form-data-before-submitting-it-to-the-api

// request result
// data : {
// attribute1: 'value1',
// attribute2: 'value2',
// file.entryName: FileObj
// }
//
// request result i want
// data : {
// attribute1: 'value1',
// attribute2: 'value2',
// }
// file.entryName: FileObj
//
onFinish({
attribute1: "..."
attribute2: "..."
file.entryName: FileObj
})


// https://refine.dev/docs/api-reference/antd/hooks/form/useForm/#how-can-i-change-the-form-data-before-submitting-it-to-the-api

// request result
// data : {
// attribute1: 'value1',
// attribute2: 'value2',
// file.entryName: FileObj
// }
//
// request result i want
// data : {
// attribute1: 'value1',
// attribute2: 'value2',
// }
// file.entryName: FileObj
//
2 Replies
refine-support-bot
Hi, I am refine support bot :wave:. I am here to help you with your question. I searched for the answer to your question in the refine documentation and found an answer! 🏆 If this is the answer you need, then we are very lucky. If not, please wait for someone from the refine core team or the community to try to help you.
Answer: You can send an attribute other than data to the request in "onFinish" by using the transformValues option in the hook's options. SOURCES: ./docs/api-reference/mantine/hooks/form/useForm.md
national-gold
national-gold16mo ago
Hi, sorry i don't understand what yo try to achive. yes you can add any value to here. what is the error ?
onFinish({
attribute1: "..."
attribute2: "..."
file.entryName: FileObj
})
onFinish({
attribute1: "..."
attribute2: "..."
file.entryName: FileObj
})
Can you help me understand a little more? 😦 oh i guess i understand. do you wanna add another field to request payload ? as you can see here data provider works with that way https://github.com/refinedev/refine/blob/next/packages/strapi-v4/src/dataProvider.ts#L266 - you can override data provider update function https://refine.dev/docs/faq/#how-i-can-override-specific-function-of-data-providers if you need that customization in all functions, ofc you can use strapi-v4 data-provider as a starter