Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

raobilal4822's avatar

Radio button by default select true is not working

I want select the radio button by default selected true but it is not working why and how to

                                      ->label('Value')
                                      ->live()
                                      ->options([
                                          'true' => 'True',
                                      ])
                                      ->visible(function ($get) {
                                          $moduleName = $get('../../module');
                                          $fieldName = $get('field');
                                          if (!$moduleName || !$fieldName) return false;
                                          $module = ModuleEnum::fromName($moduleName);
                                          return $module->getFieldType($fieldName) === 'boolean';
                                      })
                                      ->default('true')
                                      ->reactive(),
0 likes
1 reply
LaryAI's avatar
Level 58

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 options and the value in default() 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 true and false options 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.

Please or to participate in this conversation.