FilamentF
Filament11mo ago
6 replies
Rolland

How to make a list of action in custom modal unique?

<?php

namespace App\Filament\Resources\Inventories\RequisitionResource\Tables\Actions\Rfp;

class RfpDeleteAction extends BaseRequestAction implements HandleCustomActionInterface
{
    public function getIdentifier(): string
    {
        return 'delete_rfp_action';
    }

    public function getLabel(): string
    {
        return 'Delete RFP';
    }

    public function getIcon(): string
    {
        return 'heroicon-s-trash';
    }

    public function getColor(): array|string|null
    {
        return Color::Red;
    }

    public function setUp(): void
    {
        parent::setUp();
        $this->requiresConfirmation();
        $this->form($this->getFormSchema());
        $this->action($this->handleAction(...));
        $this->slideOver(false);
    }

    public function handleAction(array $data): void
    {
        // delete action
    }
}


<div class="space-y-4 p-4">
    @foreach ($record->rfpStages as $rfpStage)
        <div
            class="rounded-xl border border-gray-300 bg-white shadow-sm dark:border-gray-700 dark:bg-gray-800 hover:bg-gray-50 dark:hover:bg-gray-700 transition duration-300">
            <div class="p-4 flex justify-between items-start">
                <div class="space-y-2">
                    //
                </div>

                <div class="flex gap-x-2">
                    {{ $action->getModalAction('edit') }} // here
                    {{ $action->getModalAction('delete') }} // here
                </div>
            </div>
        </div>
    @endforeach
    <div>
        {{ $action->getModalAction('create') }} // here
    </div>
</div>


When I try to delete an item from the list, all the delete buttons are being triggered instead of just the one I clicked. I know I need to add a unique ID to each button's action to fix this, but I'm not sure how to implement it. Could anyone guide me? Thank you.
preview.png
Solution
I don't think they are all being triggered at all, I think the loader is being triggered and the loader is just checking what's clickable. You can try wire keying each action to try to isolate it.
Was this page helpful?