HeaderAction disappears after usage.

I've got this action:
<?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 ?? '';
}
}
With view:
<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>
Code works, but after change, the components gets detached. How to prevent the action from disappearing from the header actions?
5 Replies
toeknee
toeknee4d ago
Can you explain what you mea by detached?
Nijholt
NijholtOP4d ago
First I got this
No description
Nijholt
NijholtOP4d ago
After using the component:
No description
toeknee
toeknee4d ago
I suspect you need to key the wire or it's the choicesjs not re-rendering on refresh
Nijholt
NijholtOP3d ago
Was a conditional thing. I was only showing the action when a relation was loaded. Somehow the relation disappears when using the action, causing the action to disappear too.

Did you find this page helpful?