F
Filament15mo ago
mxc

Select component with searchable & live?

Hi all, I have a select box populated via a query that has the live method enabled as there is a dependent select whose options change depending on what is selected in the parent. If I enable searchable on the parent select the functionality doesn't work. A red box is placed around the parent select. The dependent select is not updated. It works fine if searchable is not enabled. I have tried adding debounce(600) as I have seen suggested by it doesn;t change the outcome.
Section::make()->schema([
Select::make('Customer')->options(Models\Customer::all()->pluck('CompanyName', 'ID')
->sort(function ($customer1, $customer2) {
return strtolower($customer1) <=> strtolower($customer2);
}))->label('Customer')
->live(),
//->searchable(),
// })->reactive(),
//->debounce(600),
Select::make('Contact')
->options(function (Get $get): Collection {
$customer_id = $get("Customer");
$results = Models\CustomerContact::where('CustomerId', $customer_id)->pluck('Name', 'CustomerContactID')
->sort(function ($customer1, $customer2) {
return strtolower($customer1) <=> strtolower($customer2);
});
return $results;
})
->label('Contact')
->searchable(),
Section::make()->schema([
Select::make('Customer')->options(Models\Customer::all()->pluck('CompanyName', 'ID')
->sort(function ($customer1, $customer2) {
return strtolower($customer1) <=> strtolower($customer2);
}))->label('Customer')
->live(),
//->searchable(),
// })->reactive(),
//->debounce(600),
Select::make('Contact')
->options(function (Get $get): Collection {
$customer_id = $get("Customer");
$results = Models\CustomerContact::where('CustomerId', $customer_id)->pluck('Name', 'CustomerContactID')
->sort(function ($customer1, $customer2) {
return strtolower($customer1) <=> strtolower($customer2);
});
return $results;
})
->label('Contact')
->searchable(),
2 Replies
DrByte
DrByte15mo ago
I know this may sound unrelated, but does removing the sort solve the problem? (like, why not put the sort into the db query instead of sorting the results after they're returned?)
mxc
mxcOP15mo ago
Thanks for the tip. I used orderBy for the sorting. It didn't solve my problem. I have in the meantime created another form with different models and linked select components and it works fine. I have no idea what the difference betweenthem is that causes the 1 to work and the other not. I am investigating. The code is the same excpet for the models being queried.

Did you find this page helpful?