huppeldepuppel
huppeldepuppel
FFilament
Created by huppeldepuppel on 10/1/2024 in #❓┊help
Modal with dynamic actions
Ah perfect. I ended up using ik like this:
<div wire:click="$dispatch('pickBlock', {'blockType':'{{$blockType}}'})"></div>
<div wire:click="$dispatch('pickBlock', {'blockType':'{{$blockType}}'})"></div>
and now it works! Thanks alot!
7 replies
FFilament
Created by huppeldepuppel on 10/1/2024 in #❓┊help
Modal with dynamic actions
Yeah, I know.. Sorry about that. The thing is, I feel like I might be on the wrong track from the start, so I hesitated to share what I have so far. I might need a completely different approach, but here’s what I’ve got up to now: In my Resource headerActions() this Action:
Action::make('testform')
->action(function (array $data, array $arguments): void {
dd('action', $data, $arguments);
})
->modalContent(function (): View {
return view('filament.testform-launcher');
}),
Action::make('testform')
->action(function (array $data, array $arguments): void {
dd('action', $data, $arguments);
})
->modalContent(function (): View {
return view('filament.testform-launcher');
}),
The app\filament\testform-launcher:
<div>
@livewire('testform',['data' => $this->data])
</div>
<div>
@livewire('testform',['data' => $this->data])
</div>
The app\Livewire\Testform.php:
class Testform extends Component implements HasForms, HasActions
{
use InteractsWithForms;
use InteractsWithActions;

public ?array $data = [];

// rest of the component

public function pickItemAction(): Action
{
return Action::make('pickItemAction')
->action(function (array $arguments) {
$blockType = $arguments['blockType'];
dd($blockType);
});
}
}
class Testform extends Component implements HasForms, HasActions
{
use InteractsWithForms;
use InteractsWithActions;

public ?array $data = [];

// rest of the component

public function pickItemAction(): Action
{
return Action::make('pickItemAction')
->action(function (array $arguments) {
$blockType = $arguments['blockType'];
dd($blockType);
});
}
}
And the resources\views\livewire\testform.blade.php:
<div>
Add new block:
@foreach (['Foo','Bar'] as $blockType)
{{ $this->pickItemAction->label($blockType)(['blockType'=>$blockType]) }}
@endforeach

<x-filament-actions::modals/>
</div>
<div>
Add new block:
@foreach (['Foo','Bar'] as $blockType)
{{ $this->pickItemAction->label($blockType)(['blockType'=>$blockType]) }}
@endforeach

<x-filament-actions::modals/>
</div>
What happens now, is I'm able to click on the 2 buttons in the modal, and then the method Testform->pickItemAction() will be called, but what I want is that an Action in my Resource is being calls, since I want to change something there...
7 replies