#community-help

Suppressing Empty Option in Refinement Lists

TLDR Keith asked how to suppress an empty option in a refinement list. Jason provided instructions for using the transform items function to do so.

Powered by Struct AI
Dec 17, 2021 (25 months ago)
Keith
Photo of md5-49c23d5dc46241ca1af5233658633765
Keith
08:55 PM
Hey Jason I have another one for ya; in my refinement lists, if an item doesn’t have the field set, it shows an empty option. Is there any way I can suppress that from showing?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
08:57 PM
08:57
Jason
08:57 PM
You’re using react instantsearch IIRC right?
Keith
Photo of md5-49c23d5dc46241ca1af5233658633765
Keith
08:58 PM
I’m using the Instantsearch.js adapter
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
08:59 PM
The adapter can be used with react, vue or vanilla js versions of instantsearch…

Here’s the instantsearch.js version of transform items: https://www.algolia.com/doc/api-reference/widgets/refinement-list/js/#widget-param-transformitems
Keith
Photo of md5-49c23d5dc46241ca1af5233658633765
Keith
09:00 PM
What would you suggest I transform the item to if it’s blank?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
09:00 PM
You can just remove the item from the list if it is blank