Triggering editaction on Stat click

Hi all, I have been trying to add a click event to trigger a "editAction". The event gets dispatched, but the modal (/slideover) does not show. When I trigger the action directly, the modal does show. This is how I am trying to achieve this:
return [
Stat::make($this->widget->name, reset($stats))
->description(new HtmlString($this->widget->description))
->extraAttributes([
'class' => 'cursor-pointer widget-edit-hover transition-all duration-300 ease-in-out',
'wire:click' => "\$dispatch('widget-edit', { id: " . $this->widget->id . " })",
])
->descriptionIcon('heroicon-m-arrow-trending-up')
->color($this->widget->color)
];
return [
Stat::make($this->widget->name, reset($stats))
->description(new HtmlString($this->widget->description))
->extraAttributes([
'class' => 'cursor-pointer widget-edit-hover transition-all duration-300 ease-in-out',
'wire:click' => "\$dispatch('widget-edit', { id: " . $this->widget->id . " })",
])
->descriptionIcon('heroicon-m-arrow-trending-up')
->color($this->widget->color)
];
#[On('widget-edit')]
public function editDashboardAction(string $id): EditAction
{
$widget = Widget::query()->find($id);
ray($widget);
return EditAction::make('editDashboard')
->model(Widget::class)
->record($widget)
->form(Widget::form())
->after(function () {
$this->dispatch('$refresh');
})
->slideOver();
}
#[On('widget-edit')]
public function editDashboardAction(string $id): EditAction
{
$widget = Widget::query()->find($id);
ray($widget);
return EditAction::make('editDashboard')
->model(Widget::class)
->record($widget)
->form(Widget::form())
->after(function () {
$this->dispatch('$refresh');
})
->slideOver();
}
- I have confirmed the function gets called on Click - I have confirmed the modals code itself is loaded on the page Thanks for the help!
Solution:
OK, I figured it out: ``` #[On('widget-edit')] public function widgetEdit(string $id): void {...
Jump to solution
2 Replies
Auth1Specialist
Auth1SpecialistOP9h ago
Ah, I have made some progress here. The issue seems to be the action isn't mounted. So fiddling with mounting the action before calling it. Will report back with a full solution if I find one.
Solution
Auth1Specialist
OK, I figured it out:
#[On('widget-edit')]
public function widgetEdit(string $id): void
{
$this->mountAction('editDashboardAction', ['id' => $id]);
}
#[On('widget-edit')]
public function widgetEdit(string $id): void
{
$this->mountAction('editDashboardAction', ['id' => $id]);
}
The click events dispatches this event. Which will trigger the modal to open.

Did you find this page helpful?