How to properly use a boolean Select field.

Hi there, Having some trouble working out how boolean select fields are meant to work. If I call Select::make('my_field')->boolean('Yes', 'No', 'Select an option'), then it doesn't actually work if I pre-fill that field with an actual boolean. I suspect this is because the options are set to 0 and 1 by this and true !== 1. How is this intended to be used? Should the field actually be treated as a number and cast to a boolean after the fact?
2 Replies
LeandroFerreira
try
Select::make('my_field')
->boolean()
->formatStateUsing(fn ($state): int => $state ? 1 : 0)
Select::make('my_field')
->boolean()
->formatStateUsing(fn ($state): int => $state ? 1 : 0)
darrena092
darrena092OP2y ago
Will try that, thanks!
Want results from more Discord servers?
Add your server