diff --git a/packages/forms/src/Components/Concerns/CanDisableOptionsWhenSelectedInSiblingRepeaterItems.php b/packages/forms/src/Components/Concerns/CanDisableOptionsWhenSelectedInSiblingRepeaterItems.php index 94abc9b430..979b6685a4 100644 --- a/packages/forms/src/Components/Concerns/CanDisableOptionsWhenSelectedInSiblingRepeaterItems.php +++ b/packages/forms/src/Components/Concerns/CanDisableOptionsWhenSelectedInSiblingRepeaterItems.php @@ -2,6 +2,7 @@ namespace Filament\Forms\Components\Concerns; +use BackedEnum; use Filament\Forms\Components\Contracts\CanDisableOptions; use Filament\Schemas\Components\Component; use Illuminate\Support\Arr; @@ -27,7 +28,14 @@ trait CanDisableOptionsWhenSelectedInSiblingRepeaterItems ->after('.'), ) ->flatten() - ->diff(Arr::wrap($state)) + ->map(function (mixed $siblingItemState): mixed { + if ($siblingItemState instanceof BackedEnum) { + return $siblingItemState->value; + } + + return $siblingItemState; + }) + ->diff(Arr::wrap(($state instanceof BackedEnum) ? $state->value : $state)) ->filter(fn (mixed $siblingItemState): bool => filled($siblingItemState)) ->contains($value); }); diff --git a/tests/src/Forms/Components/RepeaterTest.php b/tests/src/Forms/Components/RepeaterTest.php index 71abf0cb39..ac522cc717 100644 --- a/tests/src/Forms/Components/RepeaterTest.php +++ b/tests/src/Forms/Components/RepeaterTest.php @@ -1,6 +1,7 @@ saveRelationships(); })->throws(Exception::class, 'The relationship [missing] does not exist on the model [Filament\Tests\Fixtures\Models\Post].'); +it('can use select options from an enum with `disableOptionsWhenSelectedInSiblingRepeaterItems()`', function () { + $undoRepeaterFake = Repeater::fake(); + + livewire(TestComponentWithEnumSelectRepeater::class) + ->fillForm([ + 'alternatives' => [ + ['letter' => TestLetterEnum::A], + ['letter' => TestLetterEnum::B], + ], + ]) + ->assertFormSet([ + 'alternatives' => [ + ['letter' => TestLetterEnum::A], + ['letter' => TestLetterEnum::B], + ], + ]); + + $undoRepeaterFake(); +}); + class TestComponentWithRepeater extends Livewire { public function form(Schema $form): Schema @@ -216,3 +237,27 @@ class TestComponentWithRepeater extends Livewire ->statePath('data'); } } + +class TestComponentWithEnumSelectRepeater extends Livewire +{ + public function form(Schema $form): Schema + { + return $form + ->schema([ + Repeater::make('alternatives') + ->schema([ + Select::make('letter') + ->options(TestLetterEnum::class) + ->disableOptionsWhenSelectedInSiblingRepeaterItems(), + ]), + ]) + ->statePath('data'); + } +} + +enum TestLetterEnum: string +{ + case A = 'A'; + case B = 'B'; + case C = 'C'; +}