Instantsearch.js refinementList widget with searchForFacetValues: true
leads to template/rendering error when there are no results
#2087
Labels
When adding an instantsearch.js refinementList widget, a user can choose to define a template string/function to render facets. In the case where a user wants to allow searchable facets, whether or not a refinementList template is defined, the widget does a great job of rendering sensible markup when there are results...
However, when searching the refinement list for facet values AND there are NO relevant results returned by the API, an error is thrown in the browser:
Template must be 'string' or 'function', was 'undefined' (key: noResults)
The apparent solution here is to simply add the
noResults
property to the templates object that is passed to the refinementList widget declaration. However, I could not find any explanation of this in any guides...I see that it is mentioned here but only in the params list.
There is little info in any guide I found concerning the topic of how to properly implement searchableAttributes, attributesForFaceting, or search-for-facet-values templating
( i.e here, here, or here).
I think it may be worthwhile to explicitly state somewhere in the instantsearch/templates guide that this
noResults
prop should be specified when building a searchable facets list.Vincent suggested that this behavior is actually a bug:
"...by default if you do not provide the template for no results in the refinementList it should degrade nicely. If that's not the case then it's a miss"
I agree.
Here is a JS Fiddle I just wrote to demonstrate this issue. See error in browser dev console when searching with a query string that doesn't return results in the "Publisher" refinement list (e.g. a query like
awdawdawd
)https://jsfiddle.net/aw30jpud/
The text was updated successfully, but these errors were encountered: