How to set a default on a searchable Select
When I make my Select searchable() it prevents the default value getting set. Is there a way around this?
Select::make('status')
->options([
'draft' => 'Draft',
'reviewing' => 'Reviewing',
'published' => 'Published',
])
->searchable() //When I remove this the default gets set ok
->selectablePlaceholder(false)
->default('draft');
5 Replies
If you are using the panel builder, this should work on the create page.
https://filamentphp.com/docs/3.x/forms/fields/getting-started#setting-a-default-value
If you are using the form builder, make sure you added
$this->form->fill()
in the mount method
https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component#adding-the-formIt's the form builder. And I do already have $this->form->fill() in the mount method.
Any console errors?
No, none.
Does that change anything? I would also try ->default(['draft']) on the basis searchable might be searching an array, possibly.