F
Filament7mo ago
zen69

Select value when using allowHtml

Hello! I'm using allowHtml on my selection with a relationship. My issue is, since I'm rendering the options with the user avatar and name, The value passed is no longer the id that I need, but the whole Html used to render the options. My question is how can I get just the value without the html please:
Select::make('user_id')
->label(fn() => __('Collaborateur'))
->allowHtml()
->relationship(
name: 'user',
titleAttribute: 'name',
modifyQueryUsing: fn(Builder $query) => $query>withoutRoles([
config('filament-shield.super_admin.name'), config('filament-shield.panel_user.name')
])

)->searchable(['name', 'email'])
->searchPrompt(__('Rechercher par nom ou email'))
->getOptionLabelFromRecordUsing(fn(Model$record) => Blade::render(
'<x-filament::avatar
src="' . filament()>getUserAvatarUrl($record) . '"
size="sm"
class="inline mr-2"
/> ' . $record?->name . ' - ' . $record->email
)
)->required()
Select::make('user_id')
->label(fn() => __('Collaborateur'))
->allowHtml()
->relationship(
name: 'user',
titleAttribute: 'name',
modifyQueryUsing: fn(Builder $query) => $query>withoutRoles([
config('filament-shield.super_admin.name'), config('filament-shield.panel_user.name')
])

)->searchable(['name', 'email'])
->searchPrompt(__('Rechercher par nom ou email'))
->getOptionLabelFromRecordUsing(fn(Model$record) => Blade::render(
'<x-filament::avatar
src="' . filament()>getUserAvatarUrl($record) . '"
size="sm"
class="inline mr-2"
/> ' . $record?->name . ' - ' . $record->email
)
)->required()
2 Replies
younicke_gold
younicke_gold5mo ago
anybody has idea on thow to achieve this? i also need this functionality on my app.. would really appreciate if anybody could give us any idea on how to achieve this.
krekas
krekas5mo ago
just tried. for me it seems to be working in the authors code the avatar shouldn't even be shown as he uses the native select adding native(false) should fix problem at least i think this worked for me