wire-elements/modal

Opening Modal Failed

Closed this issue · 1 comments

Hi there,

i planned to imploment spotlight to my project all day today, and in the process of implomenting i noticed an issue, it could be from my side, or the package side, as there is no error messages in the console. "Its clearer than my life xD"

however, i was trying to open a modal "Livewire-modal-element" using the following:

  public function execute(Spotlight $spotlight, Category $category)
    {
        $spotlight->dispatch('openModal')->to(CategoryModal::class);
    }

but nothing get open or closed, but when i use the old school method using a button that has a $dispatch, it wors just fine.

any idea in how to fix it?

Additional, here is my modal component

<?php

namespace App\Livewire\Dashboard\Catalog\Category;

use App\Livewire\Forms\Dashboard\Catalog\CategoryForm;
use App\Models\Catalog\Category;
use Jantinnerezo\LivewireAlert\LivewireAlert;
use Livewire\WithFileUploads;
use LivewireUI\Modal\ModalComponent;

class CategoryModal extends ModalComponent
{
    use LivewireAlert, WithFileUploads;

    public ?Category $category = null;
    public CategoryForm $form;

    public $categories = [];

    public function mount(Category $category = null): void
    {
        if ($category->exists) {
            $this->form->setCategory($category);
        }

        $this->categories = Category::whereNull('parent_id')->get();
    }

    public function save()
    {
        $response = $this->form->save();

        $this->closeModal();

        $this->dispatch('refresh')->to(CategoryComponent::class);

        $this->alert('success', $response ?? 'undefined');
    }

    public function render()
    {
        return view('livewire.dashboard.catalog.category.category-modal');
    }
}

Why are you trying to open a modal server-side rather than client-side? What's the logic