Select Field search not reloading options after clearing search

I have a select field that I'm searching on. It searches through an array of data. Searching works, but if you search, then backspace to clear the search, only the last search is appearing. I have to then add a space and to get all the options again. (See video) Am I doing something wrong? Thanks!
Select::make('item')
->searchable()
->preload()
->searchDebounce(200)
->options(fn () => static::getItems())
->getSearchResultsUsing(function (string $search) {
return static::getItems($search);
}),
Select::make('item')
->searchable()
->preload()
->searchDebounce(200)
->options(fn () => static::getItems())
->getSearchResultsUsing(function (string $search) {
return static::getItems($search);
}),
protected static function getItems(string $search = null)
{
$items = [
'foo',
'bar',
];

return collect($items)
->filter(function ($item) use ($search) {
if (blank($search)) {
return true;
}

return Str::contains($item, $search);
})
->toArray();
}
protected static function getItems(string $search = null)
{
$items = [
'foo',
'bar',
];

return collect($items)
->filter(function ($item) use ($search) {
if (blank($search)) {
return true;
}

return Str::contains($item, $search);
})
->toArray();
}
3 Replies
Dan Harrin
Dan Harrin2y ago
Its probably a small bug relating to our Choices.js implementation (AJAX searching doesnt come out of the box and we had to hack it in). I don't think it's too much of a dealbreaker though
Kenneth Sese
Kenneth SeseOP2y ago
Ok..and yes it appears to be a small bug...I checked out some other implementations on the filament demo page. Now that I know it's not me, I'll see if I can figure out the bug and submit a PR. Thanks
Kenneth Sese
Kenneth SeseOP2y ago
PRed a "fix" for this that mostly fixes this bug: https://github.com/filamentphp/filament/pull/6431
GitHub
Fix options not resetting after backspacing by archilex · Pull Requ...
This PR mostly fixes resetting the select field options when backspacing. Currently, when you search in a select field and then backspace to clear the search term, it will NOT reset to show all the...
Want results from more Discord servers?
Add your server