I have a SimpleForm inside an edit component, in which I have an ImageInput. My goal is to upload the image when selecting it and assigning the URL returned by the response of /upload API into the record object and save the JSON payload with the correct URL instead of localhost.
function CategoryEdit() {
return (
<Edit
title={<Title page="Category" title="name" />}
actions={<CategoryEditActions />}
aside={<Aside />}
>
<SimpleForm t`your text`oolbar={<CustomToolbar />}>
<TextInput source="id" disabled label="ID" fullWidth />
<TextInput source="name" required fullWidth />
<TextInput source="description" multiline fullWidth />
<ImageInput source="image" label=" Image" accept="image/*">
<ImageField source="src" title="title" />
</ImageInput>
</SimpleForm>
</Edit>
);
}
I have tried to solve it using onDrop, but I am not able to modify the edit record manually inside onDrop.
2
Answers
It seems to me that these operations are best done in the DataProvider, where you can upload an image, and then modify the record before submitting. There is a similar example here but there the image is loaded as part of the record.
I had a similar issue with
FileInput
component, fixed by creating aFileInputAsync
component.Solution 1 : From scratch
useInput
This is a simple approch example to start to resolve your problem with react admin
Solution 2 : From
ImageInput
componentIn all cases, for user experience, mind to disable form submit button during uploading and show error and info notifications