How can I convert this json Object to formData? I’m getting this json in onFinish function
{
design_name_code: "Hiroko Lloyd",
design_name: "Darius Huff",
design_photo: [],
fabrics: [
{
fabricName: "Georgette",
colors: [
{
color: "red"
},
{
color: "pink"
}
]
},
{
fabricName: "Silk",
colors: [
{
color: "Yellow"
}
]
}
],
designers: [
"643a33012e54c21e2409fa86"
]
}
onFinish function
const onFinish = (values) => {
const formData = new FormData();
formData.append("design_name", values.design_name);
formData.append("design_name_code", values.design_name_code);
if (values.design_photo) {
formData.append("design_photo", designImage);
}
values.fabrics?.forEach((data, index) => {
formData.append(`fabric[${index}].fabric_name`, data.fabricName);
data.colors.forEach((clr, clrIndex) => {
formData.append(`fabric[${index}].colors[${clrIndex}].color`, data.colors[clrIndex].color);
})
});
values.designers?.forEach((data, index) => {
formData.append(`designer[${index}]`, data)
})
console.log(values);
};
here when the form submit, I get the json object (as you can above), after that I create the formData of that json Object (you can see on onFinish function), here I’m facing a challenge in fabrics
object