Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 918
Louise Klodt Avatar asked Oct 17 '22 07:10

Louise Klodt


1 Answers

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

like image 116
kunal pareek Avatar answered Oct 21 '22 07:10

kunal pareek