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.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | 3300204-12--multiple_searchbox_widgets.patch | 2.61 KB | drunken monkey |
Comments
Comment #2
ronchica commentedExperiencing the exact same thing. Whichever searchable facet that appears first is the one that works.
Comment #3
ronchica commentedI took a look at this and have a small fix in searchbox.js that solves the problem for me. Attaching the patch.
Comment #4
laura.gatesComment #5
laura.gatesThis patch applied; however, it did not work for me with Facets 2.0.5 and 9.4.8 using php 8.1
Comment #6
vasyok commentedHi 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.
Comment #7
knurg commentedWorks great :)
Please commit :)
Comment #8
knurg commentedThis 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.
Comment #9
knurg commentedThis should fix both issues stated above :)
Comment #10
ronchica commentedThank 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.
Comment #11
mlncn commentedGuess 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.
Comment #12
drunken monkeyThe 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
$facetsWidgetSearchboxinside the event handler, which I suspect as the main problem. Also it avoids usingthejQuery.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.
Comment #13
amir simantov commentedThank 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!
Comment #16
borisson_Committed to both 2.x and 3.x