F
Filament10mo ago
lazydog

CheckboxList SelectAll by default

How can I make my CheckboxList all checked by default?
3 Replies
Positiverain
Positiverain10mo ago
EditAction::make()
->mutateFormDataUsing(function (array $data): array {
$data['checkbox_list_items'] = Model::all()->pluck('id');

return $data;
})
EditAction::make()
->mutateFormDataUsing(function (array $data): array {
$data['checkbox_list_items'] = Model::all()->pluck('id');

return $data;
})
I personally used
ViewAction::make()
->form([...])
->fillForm(function ($record) {
return [
'checkbox_column' => $record->checkedItems()->pluck()
];
})
ViewAction::make()
->form([...])
->fillForm(function ($record) {
return [
'checkbox_column' => $record->checkedItems()->pluck()
];
})
lazydog
lazydogOP10mo ago
Thank you but how can I use this in CheckboxList Component?
Positiverain
Positiverain10mo ago
When submitting form, you'll notice that the checkboxlist will return something for $data['checkboxlistinput'], the checked items of that checkbox. By reversing this process you are pre-filling the checkboxlist component. Have to use either of those two methods above.
Want results from more Discord servers?
Add your server