Default at select fields not work

somehow at v3 the default at select field not work as simple as
Select::make('status')
->options([
'draft' => 'Draft',
'reviewing' => 'Reviewing',
'published' => 'Published',
])
->default('draft')
Select::make('status')
->options([
'draft' => 'Draft',
'reviewing' => 'Reviewing',
'published' => 'Published',
])
->default('draft')
it still show "select an option"
No description
Solution:
did you add $this->form->fill() to the mount method?
Jump to solution
15 Replies
toeknee
toeknee2w ago
Is this in edit or create context
Stevee
SteveeOP7d ago
I use it at custom page I think not work at both
Solution
LeandroFerreira
did you add $this->form->fill() to the mount method?
LeandroFerreira
Are you using a statePath?
Stevee
SteveeOP7d ago
yes I have $this->fillForm(); at mount
LeandroFerreira
could you share the whole code?
Stevee
SteveeOP7d ago
no for this case
LeandroFerreira
Did you add public $status property?
Stevee
SteveeOP7d ago
no
LeandroFerreira
did you try to add this?
Stevee
SteveeOP7d ago
but i just notice, it work if I declare it in just simple case. but in my case I need some logic like
->default(function () use ($record): ?int {
if ($record->status !== null) {
return $record->status;
}
$enabledStatuses = Status::where([
'status_id' => $record->status_id,
'enabled' => true,
])->get('id');
if ($enabledStatuses->count() === 1) {
return $enabledStatuses->first()->id;
}

return null;
})
->default(function () use ($record): ?int {
if ($record->status !== null) {
return $record->status;
}
$enabledStatuses = Status::where([
'status_id' => $record->status_id,
'enabled' => true,
])->get('id');
if ($enabledStatuses->count() === 1) {
return $enabledStatuses->first()->id;
}

return null;
})
in this case it not work
LeandroFerreira
Didn't it work?
Stevee
SteveeOP7d ago
ya this case work after I declare
public $status
public $status
LeandroFerreira
that's it. If you have another issue, it isn't related to the default() I think
Stevee
SteveeOP7d ago
ah here is my mistake thank you

Did you find this page helpful?