Changing the record for the modal of a form/action
I have tried to edit another model in a resource (form) via an action with modal. Can someone tell me how I can change the record for the modal?
I have tried the following:
1. override
resolveDefaultClosureDependencyForEvaluationByName()
method of the action. Did not work
2. I tried $this->mountUsing(fn (Form $form) => $form->model($myRecord));
to overwrite the record in the form object. So the modal opens without error but if you change something in the modal you get an error. (The error [TypeError] that the record has been changed to the wrong one again)4 Replies
I am a little confused on what you are trying? Click edit action on the row will do that? Can you explain more your approach?
I try not to edit the model via a table/action, but to edit the other model via a form/action. (Reason: convenience for the user
What is the other model? this isn't making much sense sorry.. Do you mean you want to edit a relationship in a model from the table/action?
Okay. I don't have the action in a table. I'll dig a little further.
I am currently making a plugin with which you can create customized forms as a user.
To create these forms I have a more complex form schema.
Now I have a different model, let's take "Product" as an example. Product has a relation to CustomForm. To make it more comfortable for the user. Should the user have the possibility to press a button (form/action) while editing the product and then the modal should open with the form of the CustomForm. However, for the form to work, the $record variable in the closer functions of the CustomForm schema must be executed with the CustomForm $record. Which means that I have to change the model/record in the modal. And my question is how I can convert the record from this form action in the modal.
As explained above I tried to change the model in the form of the modal with $this->mountUsing(fn (form $form) => $form->model($myRecord)); this works until the user makes any interaction.
I also tried to override resolveDefaultClosureDependencyForEvaluationByName() in the Action class to pass the CustomForm model as a record.