Select menu. Enum. How set default-selected

I got a field in DB and model, which is an enum type. Something like this: ['xxx', 'yyy', 'zzz'] In filament, I did:
return $form
->schema([
Forms\Components\Select::make('stage')
->options(['xxx', 'yyy', 'zzz'])
->default('stage')
->disablePlaceholderSelection()
return $form
->schema([
Forms\Components\Select::make('stage')
->options(['xxx', 'yyy', 'zzz'])
->default('stage')
->disablePlaceholderSelection()
In the DB, the field stage is already set to yyy. But the menu still displays xxx
4 Replies
toeknee
toeknee3mo ago
Because your xxx, yyy, zzzz will be: 1,2,3 Setup a proper enum class and do it properly https://filamentphp.com/docs/3.x/support/enums
atabegruslan
atabegruslan3mo ago
So it should be an assoc array? ['xxx'=>'xxx', 'yyy'=>'yyy', 'zzz'=>'zzz']
toeknee
toeknee3mo ago
yes but if you just do the enum class properly it'll be easy for your filters etc too
atabegruslan
atabegruslan3mo ago
Yep. Turned out to be as easy as
use App\Enums\DeliveryStage;
Forms\Components\Select::make('stage')->options(DeliveryStage::class)
use App\Enums\DeliveryStage;
Forms\Components\Select::make('stage')->options(DeliveryStage::class)
Thank you
Want results from more Discord servers?
Add your server