F
Filament2y ago
Vp

How to auto fill multiple select in Action

I have added new button and it contains multiple select, How can I make the select field auto display the name in EDIT Tables\Actions\Action::make('link-account') ->mountUsing( function (Forms\ComponentContainer $form, Customer $record) { $childCustomer = Customer::where('approver', $record->id)->pluck('id'); $form->fill([ 'approver_id' => $record->id, 'name' => $record->name.' ('.$record->idd.' '.$record->phone_number.')', 'child' => $childCustomer, ]); } ) ->form([ Forms\Components\Hidden::make('approver_id'), Forms\Components\TextInput::make('name') ->label(('Approver')) ->disabled(), Forms\Components\Select::make('child') ->label(('Child')) ->multiple() ->options(Customer::query()->active()->pluck('name', 'id')) ->searchable() ->required(), ]) ->action(function (array $data): void { dd($data); }), If it's empty then it working fine, but for edit the problem come like it diplay the ID in multi select field, not name... and in dd($data) action it comes the name, not ID Sorry for bad english
8 Replies
Dan Harrin
Dan Harrin2y ago
can you show a screenshot of that you want?
Vp
VpOP2y ago
It display ID in field, I want to display the Name, and store the ID... but on initial (edit) it display ID using my above code
Dan Harrin
Dan Harrin2y ago
does the active() scope cause the IDs to appear maybe?
Vp
VpOP2y ago
Yes, you are correct.. Is there any other way to check active() scope and get what I want? If I check using where() instead of scope the error is same.. Yes it can display name, but my problem is still same.. If i use active() scope or add another condition inside options() then this problem came.. but I need to display the active customer only..
Dan Harrin
Dan Harrin2y ago
$childCustomer = Customer::where('approver', $record->id)->active()->pluck('id'); then you wont have any options in the select that arent active
Vp
VpOP2y ago
It doesn't change anything $childCustomer = Customer::where('approver', $record->id)->active()->pluck('id') and inside FormFilter ->options(Customer::query()->pluck('name', 'id')) It always display the customer who is inactive also
Dan Harrin
Dan Harrin2y ago
i dont know, you will need to debug the queries that are being generated. this isnt a filament problem
Vp
VpOP2y ago
Thanks for the response, I can get what I want using this ->options(Customer::query()->active()->pluck('name', 'id'))->getOptionLabelUsing(fn ($value): ?string => Customer::find($value)?->name) change the label field fixed my error.. thanks @Dan Harrin
Want results from more Discord servers?
Add your server