CheckboxList group options

I have this checkbox list
CheckboxList::make('amenities')
->label('')
->columns(5)
->relationship('realEstateAmenities', 'name')
->options(RealEstateAmenity::all()
->groupBy('is_searchable')
->map(function ($amenitiesGroup) {
return $amenitiesGroup->pluck('name', 'id');
})->toArray())
CheckboxList::make('amenities')
->label('')
->columns(5)
->relationship('realEstateAmenities', 'name')
->options(RealEstateAmenity::all()
->groupBy('is_searchable')
->map(function ($amenitiesGroup) {
return $amenitiesGroup->pluck('name', 'id');
})->toArray())
. I want to group the options by is_searchable but the field waits for a string and I give it an array. Is there a way to group the options and put a label for searchable and non searchable?
16 Replies
bernhard
bernhard•17mo ago
Have you found a solution?
DianaMujoiu
DianaMujoiuOP•17mo ago
Not yet
KiaBoluki
KiaBoluki•17mo ago
@dianamujoiu try this:
...
->options( fn () => // add a closure
RealEstateAmenity::all()
->groupBy('is_searchable')
->map(function ($amenitiesGroup) {
return $amenitiesGroup->pluck('name', 'id');
})->toArray())
...
->options( fn () => // add a closure
RealEstateAmenity::all()
->groupBy('is_searchable')
->map(function ($amenitiesGroup) {
return $amenitiesGroup->pluck('name', 'id');
})->toArray())
Francisco GarcĂ­a
Francisco García•14mo ago
@awcodes Hey, can you helps us with this? or do you have some plans to support this feature? thanks in advance đź‘Ť
awcodes
awcodes•14mo ago
i would start by dropping the ->options() method, it's not meant to work with ->relationship()
Francisco GarcĂ­a
Francisco García•14mo ago
But how to achieve this? let's say how to group the options
No description
cheesegrits
cheesegrits•14mo ago
I don't think CheckboxList is "groupable" like (say) a Select multiple(). The UI you show ^^ there would have to be three separate CheckboxLists. I may be wrong, but I looked at CheckboxList component code and the Blade view, and see no support for separated groups of checkboxes. It just renders a single list with a single header.
Francisco GarcĂ­a
Francisco García•14mo ago
daccord, even checking filament shield they create collapsibles with checkbox lists
awcodes
awcodes•14mo ago
They are also doing a lot of customization to read those out and set them up that way.
Francisco GarcĂ­a
Francisco García•14mo ago
where can we post this to leave like a feature request, would be great to have a simplified group approach
awcodes
awcodes•14mo ago
I don’t know that it can be grouped like that. There’s a lot more to it. Shield has to do some serious custom stuff to get it work. It won’t be as simple as reading the group from the relationship query.
Francisco GarcĂ­a
Francisco García•14mo ago
ok, thank you all for fast responses, really kind. đź‘Ś
awcodes
awcodes•14mo ago
You could potentially query the relationship independently and build out the different checkbox components as Hugh said. But you also need to manually format them back out on save to make the relation stay intact. And that’s just due to how html handles checkboxes. Not necessarily a Filament thing.
cheesegrits
cheesegrits•14mo ago
^^^ What he said. I had a long(ish) think about how this could be done as-is, and there's no simple way that wouldn't require some complex data mutation on submit. It could potentially be baked in to Filament, as there's nothing to prevent checkboxes in the same "field" being visually separated into groups with their own heading, but it would be a non trivial PR to write.
awcodes
awcodes•14mo ago
Yea. There’s just a lot of caveats like the select/deselect all that would have a complicated solution for an edge case like this.
Want results from more Discord servers?
Add your server