F
Filamentβ€’16mo 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
Vpβ€’16mo ago
->default(2), default(key)
dyo
dyoOPβ€’16mo ago
i got error syntax error, unexpected token "default", expecting "]" what if i want to checked more than one value?
toeknee
toekneeβ€’16mo 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
Vpβ€’16mo ago
Sorry for bad answer, I confuse with columns.. πŸ˜†
amite
amiteβ€’16mo ago
Please mark as solved if this worked
dyo
dyoOPβ€’16mo ago
what if i want to checked some value in edit modal page?
toeknee
toekneeβ€’16mo 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
dyoOPβ€’16mo ago
ok thanks for the idea.. i'll try..
Want results from more Discord servers?
Add your server