getOptionLabelUsing is not working for custom option label result in Select
i cannot make it work using getOptionLabelUsing to make custom option label
Solution:Jump to solution
Here you go. Try this. You'll need to adapt to your columns:
```php
Forms\Components\Select::make('user')
->searchable()...
12 Replies
What's not working? And please be sure copy and paste code and not screenshots
@archilex im sorry, very newly here, i will elaborate more
i want to customize the label option like "NamaPerusahaan - ContactPerson" but always ended up with only "NamaPerusahaan" (screenshot below)
below is my code
Solution
Here you go. Try this. You'll need to adapt to your columns:
Basically
getSearchResultsUsing()
and getOptionLabelUsing()
need to match
Also you need to set Customer::find()
in a variable because if not it you'll be doing duplicate queries to the DB
So if you want the labels to have both NamaPerusahaan
and ContactPerson
then you need to have that as well in the search resultsi see, i understand now, is this documented in official filament v3 ?
Did that work for you?
yes! it is works for me, big love for u β€οΈ #nogay hahaha
It doesn't say that explicitly in the docs..., but the example in the docs has the two methods matching. I might make a PR to make it more clear.
Great!
because i surfing along the documentation and have no result
big thanks for you!
@archilex one more question if you have more time for this discussion π
i want to show all "NamaPerusahaan" first when first load, but again, i want to customize the label option, if i directly use it will only show "NamaPerusahaan" only in the label, but when doing search, it works perfectly for the label option, do you know something about this ? or we can use the method like inside this ?
Same thing. Use that match there instead of the
pluck
ok, i will try around, thanks!
great! it is worked after modified to