F
Filament17mo 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])

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
Actions - Table Builder - Filament
The elegant TALL stack table builder for Laravel artisans.
Solution:
Action::make('newPromo')
->extraAttributes(['wire:init' => new HtmlString('mountTableAction(\'newPromo\')')])
Action::make('newPromo')
->extraAttributes(['wire:init' => new HtmlString('mountTableAction(\'newPromo\')')])
...
Jump to solution
5 Replies
LeandroFerreira
LeandroFerreira17mo ago
Action::make('newPromo')
->extraAttributes(['wire:init' => new HtmlString('mountAction(\'newPromo\')')])
Action::make('newPromo')
->extraAttributes(['wire:init' => new HtmlString('mountAction(\'newPromo\')')])
Saade
Saade17mo ago
$this->mountAction('newPromo') on mounted should do the trick too
Anik
AnikOP17mo ago
Hi, pardon the confusion the action is in the getTableHeaderActions(), and when i try to use
$this->mountTableAction('newPromo')
$this->mountTableAction('newPromo')
I get this error https://flareapp.io/share/VmeMERjm
Flare
Typed property App\Filament\Resources\Events\EventsResource\Pages\ListEventPromo::$cachedTableActions must not be accessed before initialization - The error occurred at http://localhost:8000/admin/events/55/promos/10
Solution
LeandroFerreira
LeandroFerreira17mo ago
Action::make('newPromo')
->extraAttributes(['wire:init' => new HtmlString('mountTableAction(\'newPromo\')')])
Action::make('newPromo')
->extraAttributes(['wire:init' => new HtmlString('mountTableAction(\'newPromo\')')])
Saade
Saade17mo ago
yeah, i'm sorry, coppied the wrong thing from my codebase, use Leandro's answer
Want results from more Discord servers?
Add your server