© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
5 replies
Barney

Select field default value

Hi, Im having trouble with data editing. When I click 'Edit' on a row, the 'region' select field should show the default value, but it keeps showing 'Select an option' instead. What am I doing wrong?

Forms\Components\Select::make('region')
                ->options(Region::all()->pluck('name', 'id')->toArray())
                ->default(function (?Model $record) {
                    if ($record){
                        return $record->area->region->id;
                    }
                })
                ->live(),
                Forms\Components\Select::make('area_id')
                    ->relationship('area', 'name')
                    ->options(function (Get $get, ?Model $record) {
                        if($get('region')){
                            return Area::where('region_id',$get('region'))->get()->pluck('name', 'id');
                        }
                        if ($record){
                            return Area::where('region_id',$record->area->region->id)->get()->pluck('name', 'id');
                        }
                    })
                    ->live(),
Forms\Components\Select::make('region')
                ->options(Region::all()->pluck('name', 'id')->toArray())
                ->default(function (?Model $record) {
                    if ($record){
                        return $record->area->region->id;
                    }
                })
                ->live(),
                Forms\Components\Select::make('area_id')
                    ->relationship('area', 'name')
                    ->options(function (Get $get, ?Model $record) {
                        if($get('region')){
                            return Area::where('region_id',$get('region'))->get()->pluck('name', 'id');
                        }
                        if ($record){
                            return Area::where('region_id',$record->area->region->id)->get()->pluck('name', 'id');
                        }
                    })
                    ->live(),
Solution
Thank you! it solved my issue, for anyone asking about this, I added the mutateFormDataBeforeFill function on the Edit page
    protected function mutateFormDataBeforeFill(array $data): array
    {
        $data['region'] = Area::find($data['area_id'])->region->id;

        return $data;
    }
    protected function mutateFormDataBeforeFill(array $data): array
    {
        $data['region'] = Area::find($data['area_id'])->region->id;

        return $data;
    }
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Default value for select
FilamentFFilament / ❓┊help
3y ago
Dynamic Select field default value HELP PLEASE <3
FilamentFFilament / ❓┊help
2y ago
Select default value from select dropdown
FilamentFFilament / ❓┊help
17mo ago
Default value in Select input
FilamentFFilament / ❓┊help
2y ago