Is there a way to have the same "GlobalSearch" in Form Builder?
Is there a way to have the same "GlobalSearch" input field functionality to search existing data in the database in a Form Builder, I know there are datalists but I want to search based on so many factors and autofill that datalists won't help me with
14 Replies
What data are you storing where it needs to be morphable to any model type and searched across multiple models?
I'm storing first_name, last_name, middle_name, phone_number
And I want a functionality that enables me whenever I try to create a new user and start typing in any of these fields, it suggests previous names, once I select one of them it autofills the current form with their data
So if they are all on the same model you don’t need anything like the global search. https://filamentphp.com/docs/3.x/forms/fields/select#returning-custom-search-results
I still want to be able to enter new values
And I'm on v2
The same idea exists in v2. Check the v2 docs. As far as adding new ones that’s just createOptionForm().
https://filamentphp.com/docs/2.x/forms/fields#creating-new-records
All of this is actual in the v2 docs on the select field.
Is it only applicable in relationships?
Because it's from the users table to the users table
It's not a relationship that's what I mean
Guess i’m missing what you are actually to accomplish. Typically you would need a relationship to search and or create. But I would think there would be a relationship since your assigning user data to another model.
Right? I mean you’re not trying to fill those form field on a resource for users, correct?
Not quite, I'm filling a users form and I want the app to suggest users with similar names and/or mobile numbers that were previously entered
So you’re creating users based on existing users?
That sounds like a headache waiting to happen. Again I’m probably just misunderstanding.
You can set a custom query, check the Documentation sectio
Select::make('authorId')
->searchable()
->getSearchResultsUsing(fn (string $search) => User::where('name', 'like', "%{$search}%")->limit(50)->pluck('name', 'id'))
->getOptionLabelUsing(fn ($value): ?string => User::find($value)?->name),
->getSearchResultsUsing()
you can customize the queryThat's true
Still that won't allow me to create new users
did you try to add page actions with modal and reload selection when firing an event after creating