diff --git a/packages/forms/src/Components/Concerns/CanDisableOptionsWhenSelectedInSiblingRepeaterItems.php b/packages/forms/src/Components/Concerns/CanDisableOptionsWhenSelectedInSiblingRepeaterItems.php index 79bc5b08ff..ad8aa007de 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\Component; use Filament\Forms\Components\Contracts\CanDisableOptions; 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 224317ff71..ab12e4a889 100644 --- a/tests/src/Forms/Components/RepeaterTest.php +++ b/tests/src/Forms/Components/RepeaterTest.php @@ -1,6 +1,7 @@ fillForm([ + 'alternatives' => [ + ['letter' => TestLetterEnum::A], + ['letter' => TestLetterEnum::B], + ], + ]) + ->assertFormSet([ + 'alternatives' => [ + ['letter' => TestLetterEnum::A], + ['letter' => TestLetterEnum::B], + ], + ]); + + $undoRepeaterFake(); +}); + class TestComponentWithRepeater extends Livewire { public function form(Form $form): Form @@ -178,3 +199,32 @@ class TestComponentWithRepeater extends Livewire return view('forms.fixtures.form'); } } + +class TestComponentWithEnumSelectRepeater extends Livewire +{ + public function form(Form $form): Form + { + return $form + ->schema([ + Repeater::make('alternatives') + ->schema([ + Select::make('letter') + ->options(TestLetterEnum::class) + ->disableOptionsWhenSelectedInSiblingRepeaterItems(), + ]), + ]) + ->statePath('data'); + } + + public function render(): View + { + return view('forms.fixtures.form'); + } +} + +enum TestLetterEnum: string +{ + case A = 'A'; + case B = 'B'; + case C = 'C'; +}