Jan 11, 2025
0
Level 1
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

Selected value

Please or to participate in this conversation.