Combining preloaded options and search results in Forms\Components\Select
Good day, everyone! I would like to improve user experience with choosing a client from a list in a resource form.
The current solution is based on getSearchResultsUsing. I do search in the DB when user enters a few chars. However, the delay for the search is a bit worse than I used to have in my old admin panel with React.
I would like to preload 50-100 most frequent clients in the Select to get instant search results, but I still need to append the Select list with the other not so frequent clients I found in the DB when the user types something in the input.
Can you please give me the direction to solve this. Would appreciate it!
Solution
PK
Povilas K•16d ago
If your problem is the delay for the search from the FRONT-END, it is called by the default debounce parameter of 1 second, to avoid sending multiple server requests each time user types something.
You can lower that debounce to almost 0, but keep in mind then with every typed character you may send an unnecessary server request
Docs: https://filamentphp.com/docs/3.x/forms/fields/select#tweaking-the-search-debounce
Z
Zoltes•15d ago
@PovilasKorop yes, you were correct about the front-end source of the delay.
Thank you for the tip! It got much better.
I tested it with the debugbar and found out the value of 250 ms to be the lowest one that makes no extra requests when I type 3-4 chars.
I've also cut out requests to DB under 2 chars length
->searchDebounce(250)
->getSearchResultsUsing(fn (string $search): array =>
mb_strlen($search) > 1
?
Client::->where('name', 'like', '%'.mb_strtolower($search).'%')->limit(10)->pluck('name', 'id')->toArray()
:
[])
Filament is a collection of beautiful full-stack components for Laravel.You can get help using it on our Discord.
15KMembers
View on DiscordWant results from more Discord servers?
More PostsCurrent model in RepeatableEntryHow do I get the current model in a RepeatableEntry so I can use it in url()?how can i add requiresConfirmation when creating recordsi have trid this ```php
protected function getCreateFormAction(): Action
{
return ActionUploading new image to a prefilled spatie media file upload not working in custom page with formsI have a custom page with forms. I have multiple file inputs. The file inputs successfully shows theSelect::selectablePlaceholder(false) not working with relationshipsI have the following select component, which correctly displays as a list of the user's leads, with Select HasMany relationship with CreateOptionAccording to the docs the ability to create a new option on the fly only supports `BelongsTo` and `BRelation Manager not in modalI need from a Relation Manager to be open not in a modal but in a new page, but that page should havHow to return the Wizard to step 1 after create success in custom page.Hello, I have created a custom page using the form following schema this form saves the data into exHaving issues with spa() and https and logoutWhen put URL::forceScheme('https') in boot() in AppServiceProvider, my panel spa() does not work.
Bu