From b8c0a8f7220c82f7e2752337889e20637a661ef5 Mon Sep 17 00:00:00 2001 From: Kevin Winardi <145827247+KevinWinardi@users.noreply.github.com> Date: Mon, 21 Jul 2025 19:53:31 +0700 Subject: [PATCH 1/3] chore: update documentation link When clicking the link, it doesn't take to the correct documentation but instead to the initial installation page. It turns out the problem was that the "advanced" path was outside of the "fields". --- packages/forms/docs/03-fields/08-date-time-picker.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/forms/docs/03-fields/08-date-time-picker.md b/packages/forms/docs/03-fields/08-date-time-picker.md index 197a3204ef..d9d3fcd56c 100644 --- a/packages/forms/docs/03-fields/08-date-time-picker.md +++ b/packages/forms/docs/03-fields/08-date-time-picker.md @@ -239,7 +239,7 @@ Please note that this setting is only enforced on native date pickers. If you're There are a few differences, compared to [`disabled()`](getting-started#disabling-a-field): -- When using `readOnly()`, the field will still be sent to the server when the form is submitted. It can be mutated with the browser console, or via JavaScript. You can use [`dehydrated(false)`](advanced#preventing-a-field-from-being-dehydrated) to prevent this. +- When using `readOnly()`, the field will still be sent to the server when the form is submitted. It can be mutated with the browser console, or via JavaScript. You can use [`dehydrated(false)`](../advanced#preventing-a-field-from-being-dehydrated) to prevent this. - There are no styling changes, such as less opacity, when using `readOnly()`. - The field is still focusable when using `readOnly()`. From c8afab6eabd15d7316a529213b7efcea1255fe2e Mon Sep 17 00:00:00 2001 From: IgorPierre Date: Mon, 21 Jul 2025 16:21:26 -0300 Subject: [PATCH 2/3] fix: support enums as Select options with disableOptionsWhenSelectedInSiblingRepeaterItems --- ...ionsWhenSelectedInSiblingRepeaterItems.php | 8 ++- tests/src/Forms/Components/RepeaterTest.php | 50 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/packages/forms/src/Components/Concerns/CanDisableOptionsWhenSelectedInSiblingRepeaterItems.php b/packages/forms/src/Components/Concerns/CanDisableOptionsWhenSelectedInSiblingRepeaterItems.php index 79bc5b08ff..cd85e1ab7a 100644 --- a/packages/forms/src/Components/Concerns/CanDisableOptionsWhenSelectedInSiblingRepeaterItems.php +++ b/packages/forms/src/Components/Concerns/CanDisableOptionsWhenSelectedInSiblingRepeaterItems.php @@ -27,7 +27,13 @@ trait CanDisableOptionsWhenSelectedInSiblingRepeaterItems ->after('.'), ) ->flatten() - ->diff(Arr::wrap($state)) + ->map(function ($siblingItemState) { + if ($siblingItemState instanceof \UnitEnum) { + return property_exists($siblingItemState, 'value') ? $siblingItemState->value : $siblingItemState->name; + } + return $siblingItemState; + }) + ->diff(Arr::wrap($state instanceof \UnitEnum ? (property_exists($state, 'value') ? $state->value : $state->name) : $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..44e950b56f 100644 --- a/tests/src/Forms/Components/RepeaterTest.php +++ b/tests/src/Forms/Components/RepeaterTest.php @@ -8,6 +8,7 @@ use Filament\Tests\TestCase; use Illuminate\Contracts\View\View; use Illuminate\Support\Arr; use Illuminate\Support\Str; +use Filament\Forms\Components\Select; use function Filament\Tests\livewire; @@ -140,6 +141,26 @@ it('can remove items from a repeater', function () { $undoRepeaterFake(); }); +it('can use enum as select options 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(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'; +} From 470917c4e4fdd5a31bc1a00c576aa589c5ad00ff Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Tue, 22 Jul 2025 10:16:06 +0100 Subject: [PATCH 3/3] clean up --- ...isableOptionsWhenSelectedInSiblingRepeaterItems.php | 10 ++++++---- tests/src/Forms/Components/RepeaterTest.php | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/forms/src/Components/Concerns/CanDisableOptionsWhenSelectedInSiblingRepeaterItems.php b/packages/forms/src/Components/Concerns/CanDisableOptionsWhenSelectedInSiblingRepeaterItems.php index cd85e1ab7a..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,13 +28,14 @@ trait CanDisableOptionsWhenSelectedInSiblingRepeaterItems ->after('.'), ) ->flatten() - ->map(function ($siblingItemState) { - if ($siblingItemState instanceof \UnitEnum) { - return property_exists($siblingItemState, 'value') ? $siblingItemState->value : $siblingItemState->name; + ->map(function (mixed $siblingItemState): mixed { + if ($siblingItemState instanceof BackedEnum) { + return $siblingItemState->value; } + return $siblingItemState; }) - ->diff(Arr::wrap($state instanceof \UnitEnum ? (property_exists($state, 'value') ? $state->value : $state->name) : $state)) + ->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 44e950b56f..ab12e4a889 100644 --- a/tests/src/Forms/Components/RepeaterTest.php +++ b/tests/src/Forms/Components/RepeaterTest.php @@ -1,6 +1,7 @@