F
Filament5mo ago
Euler

How to set default in ToogleButtons?

I tried to use default('option2'), but without success.
public function form(Form $form): Form
{
return $form
->schema([
ToggleButtons::make('status')
->options([
'option1' => 'First Option',
'option2' => 'Second Option',
'option3' => 'Third Option',
])
]);
}
public function form(Form $form): Form
{
return $form
->schema([
ToggleButtons::make('status')
->options([
'option1' => 'First Option',
'option2' => 'Second Option',
'option3' => 'Third Option',
])
]);
}
6 Replies
awcodes
awcodes5mo ago
May or may not be relevant but ->default() only works in the create context. For edit it should already be set.
Euler
Euler5mo ago
I tried using ->default() when creating, but the page where I see this button starts without any enabled.
public function form(Form $form): Form
{
return $form
->schema([
ToggleButtons::make('status')
->options([
'option1' => 'First Option',
'option2' => 'Second Option',
'option3' => 'Third Option',
])
->default('option2')
]);
}
public function form(Form $form): Form
{
return $form
->schema([
ToggleButtons::make('status')
->options([
'option1' => 'First Option',
'option2' => 'Second Option',
'option3' => 'Third Option',
])
->default('option2')
]);
}
I apologize if I'm talking nonsense. I'm really new to laravel and filament.
awcodes
awcodes5mo ago
hmm. i would expect that to work.
Euler
Euler5mo ago
This is used in the Order Status of the demo filament. However, I couldn't find the demo code on github where it defines who is enabled in the status.
LeandroFerreira
LeandroFerreira5mo ago
Did you add $this->form->fill() in the mount method?
Euler
Euler5mo ago
Omg! I didn't really pay attention to that. Thank you very much, Leandro. Also needed to be included:
public ?array $data = [];
public ?array $data = [];
Solved!