How can I add a <CreateButton> (seeding the foreign key) to a ReferenceManyField in admin-on-rest

老子叫甜甜 提交于 2019-12-04 13:42:08

问题


I have an edit form for a Post record, and I'm listing the Reviews associated with that Post in a ReferenceManyField/DataGrid (ie <ReferenceManyField target="post_id" reference="reviews">). Each Review has the foreign key post_id in the DB. This is all working fine, I have an edit and delete button for each Review row.

I need to add a 'Create Review' button for the Post form, such that the post_id field in the Create Review form is pre-populated with the current id of the Post. I'm not very expert in React/Redux.


回答1:


As @Gildas has suggested above, you need a custom component for that.

1) A custom create button that routes to a create page for the review. For this you should look at how the React Router Link component documentation as well as how Admin On Rest would allocate a route for instance /:reviewId/create

2) Create a custom input component that will prefill the ID when loaded. This should be part of the location key in the props passed to your page. Ask additional questions as comments and I will try and answer them.

React and Redux are really simple things when you get the hang of them




回答2:


This is not possible directly for now: you'll have to create a custom component for that: documentation.

Someone tried to address this issue and even supplied a pull-request. Hopefully we'll be able to merge it soon: https://github.com/marmelab/admin-on-rest/pull/744

Edit: this might help https://marmelab.com/blog/2018/07/09/react-admin-tutorials-form-for-related-records.html



来源:https://stackoverflow.com/questions/45669460/how-can-i-add-a-createbutton-seeding-the-foreign-key-to-a-referencemanyfield

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!