Adding an action to a form in a livewire component not working
I have a livewire component with a form on it. I want to add a delete button, which I feel like should be pretty straight-forward. I see in the docs that I can add an anonymous action, but it's not clear on where I put it? Maybe this is obvious to others, but I've tried a few things: adding it to the mount method, using
registerActions
method on my form. I've tried following the instructions on adding it to a livewire component, including adding {{ $getAction('myaction') }}
to the blade file, but that gives an error of Undefined variable $getAction
.
How can I add an action button to a form (not a field) on a livewire component? I just want a simple delete button with a confirmation modal.
This is my form if it's helpful:
the action I'd like to add:
Solution:Jump to solution
```php
public function deleteAction(): Action
{
return Action::make('delete')
->requiresConfirmation()...
17 Replies
$form->schema()->actions([
SaveAction::make(),
DeleteAction::make()
])
or similar if memory serves, but I haven't done it on V3 yet
if you need it 'in' the form then you need an anonymous action as i linked. If you want it at the end of the form, next to save, then toeknee's method is correct.
Hmm…let me try that. I could’ve sworn I tried it and got an error, but maybe I’m crazy.
ok, I'm getting the error
Method Filament\Forms\Form::actions does not exist.
I've got InteractsWithActions trait and the HasActions contract on my classare you doing this as a cutom livewire component or on a panels / resource Page?
if it's just a custom livewire component then you wouldn't add the actions to the form, you would just render them in your view.
ok yeah it's a custom livewire component. So I would just do it how I woudl in a non-filament app? Basically add the button and wire:click to the delete method?
what if I want to show a confirmation modal, can I open that using $dispatch and pass an ID to it?
Solution
for example.
don't need to do the manual wiring up on click etc.
Ok, that's super helpful and I've almost got it working. The
->actions()
call isn't doing anything though.
Looking at the link you provided, seems to indicate I could do something like this:
However, nothing is logged.
I do see in the network tab that it's sending the appropriate data.
Here is my mount method:
I'm so close, I just must be doing something slightly wrong.
I've tried modifying like so to see what happens:
->model()
doesn't seem to do anything, and mountUsing()
produces an empty model, so it's not evidently getting the task.Figured it out:
Thanks for your help @awcodes and @toeknee !
welp...I spoke too soon. The mountUsing will log a value, but the
->action()
isn't doing anything. ergh.i think this a bug. I'm seeing others with an issue related to table actions.
https://github.com/filamentphp/filament/issues/8924
GitHub
Table row actions not working on custom livewire page · Issue #8924...
Package filament/filament Package Version v3.0.68 Laravel Version v10.26.2 Livewire Version v3.0.5 PHP Version 8.1.19 Problem description I wanted to add a row action to a table element on a custom...
fn(array $arguements, $data) => dd($data)
do you get the data?
no data, just a pause and then the page refreshes.
it's weird because if I dd() in the mountUsing method, I get a value, it's just the action method that seems to be broken.
GitHub
arguments passed to action modal content missing · Issue #8763 · fi...
Package filament/filament Package Version 3.0.62 Laravel Version 10.25.1 Livewire Version 3.0.5 PHP Version 8.1.23 Problem description when passing action arguments to modal content view it become ...
your issue is probably this one, i hope it get resolve sone day....