Form builder: Select with getSearchResultsUsing() shows id on form load instead of name
I have a product with relation
bundledProducts
that indicate the products the main product has as 'children'. Using the form builder I have a seleclist inside a repeater to be able to select these children.
The select gets it's options through a function via getSearchResultsUsing()
:
Now ProductHelper::searchProducts()
returns an array with the product_id
as key and name
as value. This works fine when searching for options.
But when loading the form the id's of the children are displayed instead of the name (in my example the product has children with id 2
and 4
). (please see attachment)
I can't figure out what I'm doing wrong here?1 Reply
Ah, I was using the
getOptionLabelFromRecordUsing
wrong... it doesn't receive a record but instead the value (product_id):
->getOptionLabelUsing(fn ($value): ?string => Product::find($value)?->name)
That's working a lot better π