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)
        ];

    #[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
    {
        $this->mountAction('editDashboardAction', ['id' => $id]);
    }

The click events dispatches this event. Which will trigger the modal to open.
Was this page helpful?