F
Filament2mo ago
Mateus

action button in topbar

Hi! I'm trying to put an action button on the topbar, but nothing is happening when I click on the action. My code is like this: Livewire component:
public function customAction(): Action
{
return Action::make('Buscar Pacote')
->requiresConfirmation()
->label('Custom Action')
->color('gray');
}
public function render()
{
return view('livewire.scan-action');
}
public function customAction(): Action
{
return Action::make('Buscar Pacote')
->requiresConfirmation()
->label('Custom Action')
->color('gray');
}
public function render()
{
return view('livewire.scan-action');
}
Hook on the panel provider:
return $panel
->renderHook(
PanelsRenderHook::GLOBAL_SEARCH_BEFORE,
fn (): string => Blade::render('@livewire(\'scan-action\')'),
)
return $panel
->renderHook(
PanelsRenderHook::GLOBAL_SEARCH_BEFORE,
fn (): string => Blade::render('@livewire(\'scan-action\')'),
)
Solution:
Ah, it’s because the name of the action doesn’t match the output in the blade file. Action::make(‘custom’) {{ $this->customAction }}...
Jump to solution
10 Replies
Lara Zeus
Lara Zeus2mo ago
what in the view: livewire.scan-action try adding <x-filament-actions::modals />
Mateus
MateusOP2mo ago
it's already like this
<div>
{{ $this->customAction }}
<x-filament-actions::modals />
</div>
<div>
{{ $this->customAction }}
<x-filament-actions::modals />
</div>
awcodes
awcodes2mo ago
based on the code you shared, there's no ->action() on the Action so, you're not telling it to actually do anything. 🙂
Mateus
MateusOP2mo ago
Really, I would like to pass an view, where I would normally use
->modalContent(fn() => view('view')),
->modalContent(fn() => view('view')),
how would I do this?
awcodes
awcodes2mo ago
ModalContent should work. The confirmation doesn’t make sense to me in that use case. 😀 but you can also do ->action(fn() => null) if you need to.
Mateus
MateusOP2mo ago
It still doesn't work, I put
dd('test')
dd('test')
inside
->action()
->action()
and it wasn't called, code:
return Action::make('Custom Action')
->label('Custom Action')
->modalContent(fn() => view('my-view'))
->color('gray')
->action(fn() => null);
return Action::make('Custom Action')
->label('Custom Action')
->modalContent(fn() => view('my-view'))
->color('gray')
->action(fn() => null);
awcodes
awcodes2mo ago
Which Action class did you import?
Mateus
MateusOP2mo ago
use Filament\Actions\Action;
Solution
awcodes
awcodes2mo ago
Ah, it’s because the name of the action doesn’t match the output in the blade file. Action::make(‘custom’) {{ $this->customAction }}
Mateus
MateusOP2mo ago
EXACTLY THAT! thank you very much @awcodes 😀
Want results from more Discord servers?
Add your server