FilamentF
Filament3y ago
Anik

opening modal on action button programmatically

https://filamentphp.com/docs/2.x/tables/actions#modals
Hi, is there any method to open to the button modal on page load/mounted
            Action::make('newPromo')
                ->button()
                ->label('Add Promo')
                ->color('primary')
                ->mountUsing(fn (ComponentContainer $form) => $form->fill([
                    'affiliate_id' => $this->affiliate->id,
                ]))
                ->action(function ($data) {
                    $data = array_merge($data,['event_id' => $this->eventId]);
                    $eventPromo = EventPromo::query()->create($data);
                    $this->notify('success', $eventPromo->name.' Promo Created');
                    return redirect()->to(EventsResource::getUrl('promos',['record' => $this->eventId]));

                })
                ->form($this->promoForm())
                ->modalHeading('Add Promo')
                ->modalActions([
                    ModalButtonAction::make('create')
                        ->label('Create')
                        ->submit('callMountedAction')
                        ->color('primary'),

                    ModalButtonAction::make('cancel')
                        ->label('Cancel')
                        ->cancel()
                        ->color('secondary'),
                ])
            //    ->extraAttributes(['isOpen' => true])
Filament
The elegant TALL stack table builder for Laravel artisans.
Solution
Action::make('newPromo')
    ->extraAttributes(['wire:init' => new HtmlString('mountTableAction(\'newPromo\')')])
Was this page helpful?