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
awcodes
awcodes16mo ago
What data are you storing where it needs to be morphable to any model type and searched across multiple models?
YoussefMaged
YoussefMagedOP16mo ago
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
awcodes
awcodes16mo ago
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
YoussefMaged
YoussefMagedOP16mo ago
I still want to be able to enter new values And I'm on v2
awcodes
awcodes16mo ago
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
awcodes
awcodes16mo ago
All of this is actual in the v2 docs on the select field.
YoussefMaged
YoussefMagedOP16mo ago
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
awcodes
awcodes16mo ago
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?
YoussefMaged
YoussefMagedOP16mo ago
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
awcodes
awcodes16mo ago
So you’re creating users based on existing users? That sounds like a headache waiting to happen. Again I’m probably just misunderstanding.
hdaklue
hdaklue16mo ago
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 query
YoussefMaged
YoussefMagedOP16mo ago
That's true Still that won't allow me to create new users
hdaklue
hdaklue16mo ago
did you try to add page actions with modal and reload selection when firing an event after creating
Want results from more Discord servers?
Add your server