Can I use custom, non-boolean values for a form toggle?
Is there an easy way to set up a toggle in Filament where the values are custom (e.g., “Value A” and “Value B” as strings) instead of the standard true/false? Or would this require handling state transformations at the resource level? I’d appreciate any advice on the cleanest approach to achieve this.
4 Replies
You can write a custom getter / setter on the model?
While true, this ‘boolean-to-string’ logic is intended only for this specific form. I believe implementing it at the model level may not be the cleanest approach for my particular scenario.
Then just use ->formatStateUsing() ?
so
Thank you @toeknee! For some reason I forgot about it.
I also combined it with
dehydrateStateUsing
for storing the values back as boolean.