Nijholt
Retrieve data from a custom Filament\Actions\Action
In my action I've got a custom view:
Now when clicking on a list item the action gets triggered, but $data remains empty:
result:
<x-filament::dropdown.list>
@foreach ($getOptions() as $key => $item)
@php
$wireClickAction = "mountAction('{$action->getName()}', { id: 12345 })";
@endphp
<x-filament::dropdown.list.item wire:click="{{ $wireClickAction }}" wire:key="{{ $key }}">
<x-filament::badge :color="$item->getColor()">
{{ $item->getLabel() }}
</x-filament::badge>
</x-filament::dropdown.list.item>
@endforeach
</x-filament::dropdown.list>
<x-filament::dropdown.list>
@foreach ($getOptions() as $key => $item)
@php
$wireClickAction = "mountAction('{$action->getName()}', { id: 12345 })";
@endphp
<x-filament::dropdown.list.item wire:click="{{ $wireClickAction }}" wire:key="{{ $key }}">
<x-filament::badge :color="$item->getColor()">
{{ $item->getLabel() }}
</x-filament::badge>
</x-filament::dropdown.list.item>
@endforeach
</x-filament::dropdown.list>
PublicationStatusAction::make('status')
->action(function ($data): void {
dd($data);
})
PublicationStatusAction::make('status')
->action(function ($data): void {
dd($data);
})
[]
5 replies
HeaderAction disappears after usage.
I've got this action:
With view:
Code works, but after change, the components gets detached. How to prevent the action from disappearing from the header actions?
<?php
declare(strict_types=1);
namespace App\Filament\Components\HeaderActions;
use App\Models\Status;
use Filament\Actions\Action;
class PublicationStatusAction extends Action
{
protected function setUp(): void
{
parent::setUp();
$this
->view('filament.actions.publication-status')
->hidden(false);
}
public static function make(?string $name = null): static
{
return parent::make($name);
}
public function getOptions(): array
{
return [
'published' => __('status_action.' . Status::STATUS_PUBLISHED),
'unpublished' => __('status_action.' . Status::STATUS_UNPUBLISHED),
];
}
public function getSelected(): string
{
return $this->getRecord()->status?->key ?? '';
}
}
<?php
declare(strict_types=1);
namespace App\Filament\Components\HeaderActions;
use App\Models\Status;
use Filament\Actions\Action;
class PublicationStatusAction extends Action
{
protected function setUp(): void
{
parent::setUp();
$this
->view('filament.actions.publication-status')
->hidden(false);
}
public static function make(?string $name = null): static
{
return parent::make($name);
}
public function getOptions(): array
{
return [
'published' => __('status_action.' . Status::STATUS_PUBLISHED),
'unpublished' => __('status_action.' . Status::STATUS_UNPUBLISHED),
];
}
public function getSelected(): string
{
return $this->getRecord()->status?->key ?? '';
}
}
<x-filament::input.wrapper>
<x-filament::input.select
x-on:change="$wire.updateStatus($event.target.value)"
class="fi-select-input"
>
@foreach ($getOptions() as $value => $label)
<option value="{{ $value }}" @if ($value === $getSelected()) selected @endif>
{{ $label }}
</option>
@endforeach
</x-filament::input.select>
</x-filament::input.wrapper>
<x-filament::input.wrapper>
<x-filament::input.select
x-on:change="$wire.updateStatus($event.target.value)"
class="fi-select-input"
>
@foreach ($getOptions() as $value => $label)
<option value="{{ $value }}" @if ($value === $getSelected()) selected @endif>
{{ $label }}
</option>
@endforeach
</x-filament::input.select>
</x-filament::input.wrapper>
7 replies