CheckboxList group options
I have this checkbox list
. 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?
. 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
Have you found a solution?
Not yet
@dianamujoiu
try this:
@awcodes Hey, can you helps us with this? or do you have some plans to support this feature?
thanks in advance đź‘Ť
i would start by dropping the ->options() method, it's not meant to work with ->relationship()
see https://filamentphp.com/docs/3.x/forms/fields/checkbox-list#customizing-the-relationship-query for modifing the relationship query
But how to achieve this?
let's say how to group the options
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.
daccord, even checking filament shield they create collapsibles with checkbox lists
They are also doing a lot of customization to read those out and set them up that way.
where can we post this to leave like a feature request, would be great to have a simplified group approach
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.
ok, thank you all for fast responses, really kind. đź‘Ś
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.
^^^
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.
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.