© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago
ouch

Custom Page -> open modal from code (dispatch)

I have custom page and i need open modal in certain condition. Is there better way than this, cuz i feel like this is terrible. And i bet that there is better way to do it, as well when i click at either of button it loads for 500ms is there way to skip animation?

class ScanProducts extends Page
{
    #[Rule('min:3', message: 'Minimální počet znaků 3')]
    #[Rule('required',message: 'Čárový kód musí být vyplněn.')]
    public $barcode = '';

    public function form(Form $form): Form
    {
      return $form
        ->schema([
            TextInput::make('barcode')...
        ]);
    }

    public function scan()
    {
        $product = Item::where('barcode',$this->barcode)->first();
        if(!$product && $this->barcode) {
   /////// OPENING MODAL HERE
            $this->dispatch('open-modal', id: 'create-product');
   /*Some other logic*/
    }

    public function redirectCreateProduct()
    {
        return $this->redirect( ItemResource::getUrl('create'));
    }
    public function closeModal()
    {
        $this->dispatch('close-modal', id: 'create-product');
    }
}
class ScanProducts extends Page
{
    #[Rule('min:3', message: 'Minimální počet znaků 3')]
    #[Rule('required',message: 'Čárový kód musí být vyplněn.')]
    public $barcode = '';

    public function form(Form $form): Form
    {
      return $form
        ->schema([
            TextInput::make('barcode')...
        ]);
    }

    public function scan()
    {
        $product = Item::where('barcode',$this->barcode)->first();
        if(!$product && $this->barcode) {
   /////// OPENING MODAL HERE
            $this->dispatch('open-modal', id: 'create-product');
   /*Some other logic*/
    }

    public function redirectCreateProduct()
    {
        return $this->redirect( ItemResource::getUrl('create'));
    }
    public function closeModal()
    {
        $this->dispatch('close-modal', id: 'create-product');
    }
}

pages blade
...
<x-filament::modal id="create-product"  icon="heroicon-o-information-circle">
 {{--CONTENT--}}
    <x-slot name="footerActions">
        <x-filament::button
            color="gray"
            wire:click="closeModal()"
        >
            Close
        </x-filament::button>
        <x-filament::button
            wire:click="redirectCreateProduct()"
        >
            Create
        </x-filament::button>
    </x-slot>
</x-filament::modal>
<x-filament-actions::modals />
...
<x-filament::modal id="create-product"  icon="heroicon-o-information-circle">
 {{--CONTENT--}}
    <x-slot name="footerActions">
        <x-filament::button
            color="gray"
            wire:click="closeModal()"
        >
            Close
        </x-filament::button>
        <x-filament::button
            wire:click="redirectCreateProduct()"
        >
            Create
        </x-filament::button>
    </x-slot>
</x-filament::modal>
<x-filament-actions::modals />
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Open modal from custom page
FilamentFFilament / ❓┊help
3y ago
Custom Page: open modal from link
FilamentFFilament / ❓┊help
3y ago
Dispatch open modal with parameters
FilamentFFilament / ❓┊help
14mo ago
Dispatch open-modal not responding
FilamentFFilament / ❓┊help
3y ago