I am using Edit
and SimpleForm
from react-admin
. How do I create a custom form to allow customised action
and type
on submit?
App.js
<Resource name="category" list={CategoryList} edit={CategoryEdit} />
index.js
<Edit actions={<CategoryEditActions />} title={<CategoryTitle />} {...props} >
<SimpleForm>
<DisabledInput source="id" />
<DisabledInput source="code" />
<TextInput source="name" />
</SimpleForm>
Here the api call would be /category/:categoryId
with PUT
request. I want to modify url to /category/:categoryId/test
with method as POST
. Is there any way to customize this?
I have handled this in my CustomDataProvider -
case UPDATE:
if(resource === 'category'){
options.method = 'POST';
url = `${apiUrl}/${resource}/${params.id}/test`;
} else {
options.method = 'PUT';
url = `${apiUrl}/${resource}/${params.id}`;
}
break;
Is there any other way to handle it?
This is the job of your dataProvider
in react-admin
(restClient
in admin-on-rest
). You'll have to create a custom one:
react-admin
: https://marmelab.com/react-admin/DataProviders.html#writing-your-own-data-provideradmin-on-rest
: https://marmelab.com/admin-on-rest/RestClients.html#writing-your-own-rest-clientYou'll have to check the resource and type then build the fetch options by yourself.