Problem/Motivation

My search api view configuration includes facets on taxonomy vocabularies, exposed filters for proximity search and keyword search. I have Ajax enabled. I would like users to narrow down their search using facets (in my case facet on city name) and then use exposed filter to proximity search. However, when users use exposed filters, it ignores the facet selection and returns independent results. This only happens when I use AJAX. Of course when I stop using Ajax, everything works fine.

Will really appreciate any help with this including ideas on how to fix this.

Steps to reproduce

  • Create a view with Facets and exposed filters
  • Use facets to narrow down search
  • Use exposed filter to search
  • Make sure you use Ajax

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork facets-3168241

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

aroopk created an issue. See original summary.

arun_kv’s picture

Title: Facets and exposed filters don't work together with Ajax and when url is encoded » Facets and exposed filters don't work together with Ajax
Issue summary: View changes
arun_kv’s picture

Issue summary: View changes
oligerd’s picture

Hi! I faced the same issue and i fixed it with solution
https://www.drupal.org/project/facets/issues/2986981#comment-13841967

andy_w’s picture

Status: Active » Needs review
Related issues: +#2826449: Ajax Facets blocks for views
StatusFileSize
new564 bytes

We are having what looks to be the same / a similar issue and it seems to be related to the fact that when facets are embedded on the page they use a relative url (e.g. /my-page) however when they use the (incredibly useful) addExposedFiltersToFacetsUrl function which allows exposed filters and facets to operate in harmony the complete url is used, and this (for us) was throwing out a number of inbound url processors.

So our fix was to use the pathname and search aspects of window.location to ensure accessing the updateFacetsBlocks method would always give a consistent response.

I'm not sure if this is helpful, but it certainly resolved our issue, and that consistency may be worth reviewing.

andy_w’s picture

StatusFileSize
new693 bytes

Actually the above solution does not cover internet explorer

jefuri made their first commit to this issue’s fork.

Oscaner’s picture

StatusFileSize
new1.11 KB
new599 bytes
qusai taha’s picture

Status: Needs review » Reviewed & tested by the community

Patch #8 Working fine with me and fixed the issue

brandonratz’s picture

Additional confirmation #8 works as expected with Facets 2.0.5

devkinetic’s picture

Is this issue for 1.5 or 2.0.x ? How is this different from the solution provided in #2986981-30: Ajax facet block seems to lose Views context (filters, etc)?

tanc’s picture

Version: 8.x-1.5 » 2.0.x-dev

Patch in #8 applies cleanly against 2.0.6 and fixes the issue I was seeing that is similar or the same as the issue in #5 with embedded facets and view with ajax enabled.

The page's path was being added to the url every time a facet was checked or unchecked. For example, on a node page containing embedded view and facets blocks with a url of /kalender, after checking and unchecking the events_relevant_for facet checkbox the url would end up looking like:

/kalender?q=/kalender%3Fq%3D/kalender%3Fq%3D/kalender%3Fq%3D/kalender%3Fq%3D/kalender%3Fq%3D/kalender%3Fq%3D/kalender%3Fq%3D/kalender%3Fq%3D/kalender%3Fq%3D/kalender%3Ff%5B0%5D%3Devents_relevant_for%3A101&f%5B0%5D=events_relevant_for%3A100

With this patch the url looks like this after checking and unchecking the events_relevant_for facet checkbox a few times:

/kalender?f%5B0%5D=events_relevant_for%3A114&keywords=
kaustubhb’s picture

I am testing this patch with the AJAX issue which is mentioned here:


Facets with AJAX not working in most of situations (https://www.drupal.org/node/3052574)

But together both the patches do not seem to work,

jrb’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new844 bytes

In Drupal 10.1.4, the patch in #8 did not work for us. In js/facets-views-ajax.js, options.url did not include the facets query string variables, so they were not getting sent in the URL that Ajax uses. I'm not sure if we're seeing something different from the people that #8 worked for or if maybe something changed in D10?

In our case, our facet was using the variable opp and our exposed form had the variables keys and open. The URL that Ajax was using when facets were active was this (formatted for clarity):

/views/ajax
?_wrapper_format=drupal_ajax
&keys=test
&open=0
&view_name=example_search
&view_display_id=block_1
&view_args=
&view_path=%2Fsearch-results
&view_base_path=search-results
&view_dom_id=c31d02539fca221547dc141fdacf4969d8c0193bd1c980cd824405906d9adf32
&pager_element=0
&_drupal_ajax=1
&ajax_page_state%5Btheme%5D=example
&ajax_page_state%5Btheme_token%5D=
&ajax_page_state%5Blibraries%5D=admin_toolbar%2Ftoolbar...

You can see that the URL there has keys and open, but is missing the opp variable which was in the URL as &opp%5B0%5D=discipline%3A255&opp%5B1%5D=eligibility%3A414 at this time.

We were able to fix this by adding code to Drupal.Ajax.prototype.beforeSend() that looks at the query string parameters in options.url, compares them those to the ones in the current URL, and adds any that are missing.

That's what this patch does.

n.ghunaim’s picture

n.ghunaim’s picture

StatusFileSize
new729 bytes
maursilveira’s picture

I ran into this same issue, and the patch #14 fixes it.

vlyalko’s picture

shubhamsprasad’s picture

Assigned: Unassigned » shubhamsprasad
Status: Needs review » Reviewed & tested by the community

Patch https://www.drupal.org/project/facets/issues/3168241#comment-15261500 worked for me.

I have performed testing as well.

I have applied following patches along with it

"Facets with AJAX not working in most of situations(https://www.drupal.org/project/facets/issues/3052574)": "https://www.drupal.org/files/issues/2024-04-18/3052574-210.patch",
                "Ajax facet block seems to lose Views context (filters, etc)(https://www.drupal.org/project/facets/issues/2986981)": "https://www.drupal.org/files/issues/2023-04-26/ajax_facet_block_views_context-2986981-35.patch"
shubhamsprasad’s picture

Assigned: shubhamsprasad » Unassigned
lisa.rae’s picture

Status: Reviewed & tested by the community » Needs work

Combination of patches in #19 are not applying to:

* Drupal 10.3.2
* Facets 2.0.8

I'm using Commerce Kickstart with Demo Commerce installed for testing. Issue is present with no patches, but patches from #19 do not apply.

Moving back to Needs Work