Gravatar for

Question by aga, Nov 18, 2015 12:44 PM

Hierarchical Facet: Disable Parent Selection


I want only the leaf nodes of the Hierarchical Facet to be selectable i.e. if the clicked node has children, then it shouldnt execute a query. So I wrote the code below to to cancel the query when I detect that the parent was clicked. This worked but I guess the click event was triggering and selecting all children. So in order to fix that I call reset on the facet. The issue will resetting the facet is that JSUI is triggering a query again.

So my question is: what is the simplest way to cancel the query and no select the children?

FYI: in our case we'll only have 2 levels of nodes

Coveo.$('#search').on('buildingQuery', function(e, args) {
  var l = Coveo.$('.CoveoHierarchicalFacet').coveo('getSelectedValues').filter(function(i,e){ return i.indexOf('|') < 0 ; }).length;
  if( l ){
    args.cancel = true;
1 Reply
Gravatar for

Answer by olamothe, Nov 18, 2015 4:36 PM

There is no option or API to directly support what you are trying to do. I would say your options are to either do a feature request for Coveo to support this cleanly, or you'll have to hack stuff yourself. If you want to handle this on your side with custom code I would suggest to look into :

Coveo.HierarchicalFacet.prototype.selectValue  / Coveo.HierarchicalFacet.prototype.toggleSelectValue

These are the method that are directly called when the user select a value. You can monkey patch those methods if you want. You could detect that the current value is not a leaf and do nothing.

Ask a question