简体   繁体   English

在react-admin中创建自定义表单

[英]Create custom form in react-admin

I am using Edit and SimpleForm from react-admin . 我正在从react-admin使用EditSimpleForm How do I create a custom form to allow customised action and type on submit? 如何创建自定义表单以允许自定义action并在提交时type

App.js App.js

<Resource name="category" list={CategoryList} edit={CategoryEdit}  />

index.js 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. 此处的api调用是带有PUT请求的/category/:categoryId I want to modify url to /category/:categoryId/test with method as POST . 我想使用POST方法将url修改为/category/:categoryId/test Is there any way to customize this? 有什么办法可以自定义吗?

I have handled this in my CustomDataProvider - 我已经在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 ). 这是您的dataProviderreact-adminrestClientadmin-on-rest )。 You'll have to create a custom one: 您必须创建一个自定义的:

You'll have to check the resource and type then build the fetch options by yourself. 您必须检查资源并键入,然后自己构建获取选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM