F
Filament2y ago
Vp

Multiple select options allow custom logic

I've already asked this one but cannot find it anymore, so here I am asking again with different topic. Is there any plan this select components accepts all my logic and render the item correctly? Base on my below code, If I used like this the name is displaying correctly in the select (chip...let call it chip) but If i try to use primaryAccount() then it cannot display name, only ID is displaying in the chip But I really need to use my custom logic (scope) in the options.. Any other work around to overcome and use my logic? Sorry for bad english and thanks in advance
Tables\Actions\Action::make('edit')
->mountUsing(fn (Forms\ComponentContainer $form, Customer $record) => $form->fill([
'approver' => $record->id,
'name' => $record->name.' ('.$record->member_id.')',
'child' => Customer::where('approver', $record->id)->pluck('id'),
]))
->form(function (Customer $record) {
return [
Forms\Components\Group::make()
->schema([
Forms\Components\Hidden::make('approver'),
Forms\Components\TextInput::make('name')->disabled(),
Forms\Components\Select::make('child')
->multiple()
->required()
->options(
Customer::query()
->where('id', '!=', $record->id)
->hasNotChild()
// ->primaryAccount()
->active()
->pluck('name', 'id')
)
->getOptionLabelUsing(fn ($value): ?string => Customer::find($value)?->name)
->searchable(),
])
->columns(2),
];
})
Tables\Actions\Action::make('edit')
->mountUsing(fn (Forms\ComponentContainer $form, Customer $record) => $form->fill([
'approver' => $record->id,
'name' => $record->name.' ('.$record->member_id.')',
'child' => Customer::where('approver', $record->id)->pluck('id'),
]))
->form(function (Customer $record) {
return [
Forms\Components\Group::make()
->schema([
Forms\Components\Hidden::make('approver'),
Forms\Components\TextInput::make('name')->disabled(),
Forms\Components\Select::make('child')
->multiple()
->required()
->options(
Customer::query()
->where('id', '!=', $record->id)
->hasNotChild()
// ->primaryAccount()
->active()
->pluck('name', 'id')
)
->getOptionLabelUsing(fn ($value): ?string => Customer::find($value)?->name)
->searchable(),
])
->columns(2),
];
})
3 Replies
Vp
VpOP2y ago
In the first image, the name "mohd mehndi" is already attached to other field so it should not come, If I apply my logic then it coming like 2nd image, logic is working but it display ID instead of name in the chip This problem comes only in multiple() in single select everything is working
Kenneth Sese
Kenneth Sese2y ago
You probably need to use getOptionLabelsUsing() as well since you’re using multiple. (Labels is plural).
getOptionLabelsUsing(fn ($values): array => Customer::find($values)?->pluck('name', 'id')->toArray())
getOptionLabelsUsing(fn ($values): array => Customer::find($values)?->pluck('name', 'id')->toArray())
Vp
VpOP2y ago
Yes, you are correct, "s" is important... and it's working.. thank you
Want results from more Discord servers?
Add your server