CheckBoxList, Enums and TextColumn display conundrum
Salut
Interesting little problem. I have a Checkbox list on the form that is populated with an Enum. This all fine and works as expected - the labels are displayed and the values are stored correctly:
On the table I want to display the the selected values
Which is where the problem arises - the column displays the stored value and not the label.
Because this is a multi-value field , stored as JSON in the model I need to cast it to
type => 'array'
If this were a simple/single value field (e.g CheckBox or Select) then I could cast it to the enum type => OrganisationTypes::class
and the correct label would be displayed in the table column.
So how do I cast the field to an array and still have the Enum return the correct labels in the table column?
Thanks for reading this far!
My enum for reference
Solution:Jump to solution
Try https://filamentphp.com/docs/3.x/forms/advanced#field-hydration
Something like below should work. not tested code
```php...
4 Replies
Solution
Try https://filamentphp.com/docs/3.x/forms/advanced#field-hydration
Something like below should work. not tested code
Yes, thank you that does the trick nicely. I was hoping that Filament would handle it automagically.
For reference this is the solution
@Tieme karma++
Filament will only do that if the cast is Enum.
Can you mark the solution, (see first comment on this thread)
Which is where the 'conflict' arose with having to cast to an array. But the solution is good