Skip to content

Commit

Permalink
Repeater - hide delete action if count < min item and confirm on dele…
Browse files Browse the repository at this point in the history
…te (#132)

* Repeater - hide delete action if count < min item and confirm on delete

* Update EditBeneficiaryPersonalInformation.php

* refactor callback

---------

Co-authored-by: Andrei Ioniță <[email protected]>
  • Loading branch information
alexPopaCode4 and andreiio authored Aug 1, 2024
1 parent f843499 commit 7ec0195
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/Concerns/RepeaterDefaultItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@

namespace App\Concerns;

use Filament\Forms\Components\Actions\Action;

trait RepeaterDefaultItems
{
protected function setUp(): void
{
parent::setUp();

$this->deletable(function (?array $state) {
if ($this->getMinItems() === null) {
return true;
}

return collect($state)->count() > $this->getMinItems();
});

$this->deleteAction(fn (Action $action) => $action->requiresConfirmation());
}

public function fillFromRelationship(): void
{
parent::fillFromRelationship();
Expand Down

0 comments on commit 7ec0195

Please sign in to comment.