F
Filament2y ago
dyo

Set default checkboxlist value

Can someone give me example how to have a checkboxlist with default value? i've tried this, but it's not working
CheckboxList::make('test')
->options([
1 => 1,
2 => 2,
3 => 3,
4 => 4,
])->default([2]),
CheckboxList::make('test')
->options([
1 => 1,
2 => 2,
3 => 3,
4 => 4,
])->default([2]),
8 Replies
Vp
Vp2y ago
->default(2), default(key)
dyo
dyoOP2y ago
i got error syntax error, unexpected token "default", expecting "]" what if i want to checked more than one value?
toeknee
toeknee2y ago
You need to pass it as an array so [2,3,4] Noting that it will only work as default on new records not editing exisitng.
Vp
Vp2y ago
Sorry for bad answer, I confuse with columns.. 😆
amite
amite2y ago
Please mark as solved if this worked
dyo
dyoOP2y ago
what if i want to checked some value in edit modal page?
toeknee
toeknee2y ago
You need to modify the data with mutating it, Filament/Livewire populate the form data on load from the mount function you see, so the form cannot set default values from values that do not exist.
dyo
dyoOP2y ago
ok thanks for the idea.. i'll try..

Did you find this page helpful?