How to trigger an action from another action?

I have an infolist which displays a record. It has two header actions. 'Edit report' and 'Enhance with AI'. 'Edit report' opens a form which allows a user to edit the record and save. When 'Enhance with AI' is clicked, I want it to open a form modal with takes some instructions which is used to improve the report(which is sent to chatGPT), I then want to open the 'Edit report' action modal and insert the enhanced report into it which the user can review and submit. How do I trigger the 'Edit report' action from 'Enhance with AI' action? Thanks
4 Replies
elben
elbenOP3w ago
Anyone has any ideas?
pratik
pratik3w ago
$this->mountAction('edit-report', ['report' => $report->id]);
elben
elbenOP3w ago
I'm able to get this working when defining an action separately in a function like:
function editReportAction() {
return \Filament\Actions\Action::make('editReport')
->label('Edit Report')
->form([
TextInput::make('test')
])
->action(function (array $data) {
dd($data);
});
}
function editReportAction() {
return \Filament\Actions\Action::make('editReport')
->label('Edit Report')
->form([
TextInput::make('test')
])
->action(function (array $data) {
dd($data);
});
}
But it's not working for actions defined in headerActions() of the infoList. The prevous action closes. Nothing else happens. I also found a method called mountInfolistAction() in InteractsWithInfolists trait. But calling this just shows the dark background which usually shows behind the modal. But it doesn't show the modal itself (with the form). What could be the reason?
pratik
pratik3w ago
Idk about that but How I got this working was registering actions with getActions method
protected function getActions(): array
{
return [
self::EditFieldAction(),
];
}

#[On('field-clicked')]
public function showFieldEditor($field_id)
{
$this->mountAction('edit-field', ['field' => $field_id]);
}
protected function getActions(): array
{
return [
self::EditFieldAction(),
];
}

#[On('field-clicked')]
public function showFieldEditor($field_id)
{
$this->mountAction('edit-field', ['field' => $field_id]);
}
element.setAttribute("onclick",`Livewire.dispatch('field-clicked',[${field.id}])`);
element.setAttribute("onclick",`Livewire.dispatch('field-clicked',[${field.id}])`);
The thing is to mount the desired action when something happens.

Did you find this page helpful?