Certainly! The issue is likely due to how the default value is being set for the radio button in Filament. The ->default() method should be passed a value directly (or a closure that returns a value), but if the form model already has a value for 'value', the default won't override it.
A few things to check and adjust:
-
Ensure the default value matches the option key:
Your options are'true'and'false'(strings), so your default should also be'true'(string), nottrue(boolean). -
Set default directly if no dynamic logic is needed:
If you always want'true'selected by default, use:->default('true') -
If using a closure, make sure it returns
'true':
Your closure is fine as long as it returns'true'. -
Check for model values:
If the form is bound to a model and the model has a value for'value', the default will not be used. Make sure the model's attribute isnullor not set. -
Full working example:
\Filament\Forms\Components\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(),
Summary of steps:
- Use
'true'(string) as the default value. - Ensure the model does not already have a value for
'value'. - If you need dynamic logic, ensure your closure returns
'true'.
If you still have issues, try clearing the browser cache or check for any JavaScript errors that might interfere with Filament's reactivity.