Default value with searchable in select component

Hi, I want to use the default() method in a Select component, it works, but if I add the searchable() method, it doesn't show the default option, is there something I'm missing?
12 Replies
Dennis Koch
Dennis Kochβ€’2y ago
Can you try ->preload()?
LeandroFerreira
LeandroFerreiraβ€’2y ago
What about static options? For ex:
Select::make('mySelect')
->options([
1 => 'Option A',
2 => 'Option B'
])
->default(1)
->searchable()
Select::make('mySelect')
->options([
1 => 'Option A',
2 => 'Option B'
])
->default(1)
->searchable()
Javier Mercedes
Javier MercedesOPβ€’2y ago
@Dennis Koch no it didn't work Looks like is selecting it, but the label is not showing up
LeandroFerreira
LeandroFerreiraβ€’2y ago
Is it a resource page? Create, edit?
Javier Mercedes
Javier MercedesOPβ€’2y ago
Is a edit form in a widget
LeandroFerreira
LeandroFerreiraβ€’2y ago
Did you try the static example? Can you share the image?
Javier Mercedes
Javier MercedesOPβ€’2y ago
No, let me see
Javier Mercedes
Javier MercedesOPβ€’2y ago
@Leandro Ferreira I just tried and is the same
Javier Mercedes
Javier MercedesOPβ€’2y ago
If I don't set a default value it shows the default text for when there is no option selected
LeandroFerreira
LeandroFerreiraβ€’2y ago
->formatStateUsing() in edit forms, but there is another option πŸ€” try it please:
Select::make('mySelect')
->options([
1 => 'Option A',
2 => 'Option B'
])
->afterStateHydrated(fn ($component) => $component->state(1))
Select::make('mySelect')
->options([
1 => 'Option A',
2 => 'Option B'
])
->afterStateHydrated(fn ($component) => $component->state(1))
Javier Mercedes
Javier MercedesOPβ€’2y ago
I'll try that later today, I have another task right now
toeknee
toekneeβ€’2y ago
Please let us know how you get on so we can close the post πŸ™‚
Want results from more Discord servers?
Add your server