mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Merge branch '3.x' into 4.x
This commit is contained in:
+9
-1
@@ -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);
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tests\Fixtures\Livewire\Livewire;
|
||||
@@ -183,6 +184,26 @@ it('throws an exception for a missing relationship', function (): void {
|
||||
->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';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user