Certainly! The issue is likely due to the value type mismatch between the radio button's option and the default value. In Filament, the radio options' keys and the default value should match exactly in both value and type.
In your code, you have:
->options([
'true' => 'True',
])
->default('true')
This should work if the value you expect to store is the string 'true'. However, if your database or model expects a boolean true, you should use true (boolean) instead of 'true' (string):
Solution 1: Use Boolean Values
->options([
true => 'True',
false => 'False', // You may want to add a false option as well
])
->default(true)
Solution 2: Use String Values Consistently
If you want to keep using strings, make sure everywhere (including validation, database, etc.) expects 'true' and 'false' as strings:
->options([
'true' => 'True',
'false' => 'False',
])
->default('true')
Summary:
- Make sure the key in
optionsand the value indefault()are the same type and value. - If you only have one option, the radio button will always be selected, but it's better to provide both
trueandfalseoptions for boolean fields.
Example with both options:
Radio::make('value')
->label('Value')
->live()
->options([
true => 'True',
false => 'False',
])
->default(true)
->visible(function ($get) {
$moduleName = $get('../../module');
$fieldName = $get('field');
if (!$moduleName || !$fieldName) return false;
$module = ModuleEnum::fromName($moduleName);
return $module->getFieldType($fieldName) === 'boolean';
})
->reactive()
Key Point:
The value in ->default() must match the key in ->options() exactly in value and type.