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

Fzoltan87's avatar

Filament 3 - Selected value

Hi everyone,

In Filament version 3, how can I ensure that only the city name is displayed for the selected value? When searching among the results, I want the "city-state" format to appear, but after selecting a value, I only need the city name to be displayed. I tried the following approach, but unfortunately, the "city-state" format still appears for the selected value as well.

Forms\Components\Grid::make('')->schema([
    Forms\Components\Select::make('city_id')
        ->label(__('fields.property_list_city'))
        ->searchable()
        ->getSearchResultsUsing(function (string $query) {
            return LocationCity::with('state')
                ->where('name', 'like', "%{$query}%")
                ->get()
                ->mapWithKeys(function ($city) {
                    return [
                        $city->id => $city->name . "\n" . '(' . $city->state->name . ')',
                    ];
                });
        })
        ->getOptionLabelUsing(function ($value) {
            $city = LocationCity::with('state')->find($value);
            if ($city) {
                return $city->name;
            }
            return null;
        })
        ->required(),

Select List

Screenshot of a comment on a GitHub issue showing an image, added in the Markdown, of an Octocat smiling and raising a tentacle.

Selected value

Screenshot of a comment on a GitHub issue showing an image, added in the Markdown, of an Octocat smiling and raising a tentacle.

0 likes
0 replies

Please or to participate in this conversation.