Problem/Motivation

When there are two facets using the Searchable list of checkboxes widget on the same page, it only works for the first one.

Steps to reproduce

When you place two different facets on a page with Search API view, e.g. like a product catalogue and set the Searchable list of checkboxes widget for both, it only works for the first one. E.g. I have a facet for product brands and product colour finished which I would like to both have the searchbox displayed. However, when I enable the Searchable list of checkboxes widget on both, the first one works correctly and the second one doesn't search for anything even though it doesn't display any kind of JS error in the console. Similarly, when I remove the searched string from the colour finish facet, it seems to also do some kind of search in the other facets with this widget because they all show "no results".

Proposed resolution

Each widget should only search in the facet list for which it has been selected.

Comments

robo.balasko created an issue. See original summary.

ronchica’s picture

Experiencing the exact same thing. Whichever searchable facet that appears first is the one that works.

ronchica’s picture

StatusFileSize
new714 bytes

I took a look at this and have a small fix in searchbox.js that solves the problem for me. Attaching the patch.

laura.gates’s picture

Status: Active » Needs review
laura.gates’s picture

Status: Needs review » Needs work

This patch applied; however, it did not work for me with Facets 2.0.5 and 9.4.8 using php 8.1

vasyok’s picture

Hi ronchica. Thanx for patch. It works.
Facets 2.0.5
PHP 8.1.3
In some cases after patching need to replace facets blocks positions.
Yes, I know about cache flush and rebuild.

knurg’s picture

Status: Needs work » Reviewed & tested by the community

Works great :)

Please commit :)

knurg’s picture

This fixes part of which is also stated here:
https://www.drupal.org/project/facets/issues/3332239

but in the other issue also the wrong behaviour of the "no results" described in this issue is fixed.

knurg’s picture

StatusFileSize
new1.21 KB

This should fix both issues stated above :)

ronchica’s picture

Thank you! I did also fix the 'no result' bit, but forgot to get back here with the patch (I made a couple other application specific updates as well). It has been running on a production site for a while.

mlncn’s picture

Version: 2.0.5 » 3.0.x-dev

Guess patches go into the 3.x branch first? Either way— this was needed to fix Searchable lists even without a second one being enabled, for me.

drunken monkey’s picture

Version: 3.0.x-dev » 2.0.x-dev
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new2.61 KB

The above patches didn’t work for me. Attached is my attempt, which works well for me and also makes the code much saner to look at. For instance, it avoids using $facetsWidgetSearchbox inside the event handler, which I suspect as the main problem. Also it avoids usingthe jQuery.next() function, which seems to me to be an unacceptable level of reliance on the HTML structure.
Unfortunately, I think it won’t be possible without at least some reliance on the HTML structure – in my patch, I relied on the fact that the <input> field is a direct child of the wrapper that contains all the relevant elements for the facet. Templates where this is not the case would still break the functionality. (But they would have been broken without this patch, too, as far as I can see, so it’s at least not a regression.)

Relying on some ancestor element with a certain CSS class being the wrapper for the facet would probably be preferrable, but not sure if we can rely on that, either. Anyways, would be trivial to adept the patch accordingly, if you think that would make more sense: just use $context = $input.closest('.wrapper-class') instead of $context = $input.parent();.

Anyways, everyone please give the attached patch a try, especially if the previous ones didn’t work for you.

@mlncn: If multiple people have tested the patch for 2.x already and it’s marked RTBC, then I don’t think switching the version makes much sense. I’ll let the maintainers decide on this.

amir simantov’s picture

Thank you, Thomas!
The patch that you supplied in #12 works for me (using the currently released version 2.0.7).

Considering there haven't been any new releases in the past three months, including this patch in the upcoming release could be a valuable opportunity.

Thanks, maintainers!

  • borisson_ committed 548e9019 on 3.0.x
    Issue #3300204 by Knurg, ronchica, drunken monkey, robo.balasko: Facets...

  • borisson_ committed ac3a42c8 on 2.0.x
    Issue #3300204 by Knurg, ronchica, drunken monkey, robo.balasko: Facets...
borisson_’s picture

Status: Needs review » Fixed
Issue tags: -facets, -facets_searchbox_widgets

Committed to both 2.x and 3.x

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.