Facets and exposed filters don't work together with Ajax

Created on 31 August 2020, about 4 years ago
Updated 11 August 2024, 3 months ago

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

🐛 Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

🇮🇳India arun_kv

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States devkinetic

    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) ?

  • 🇮🇹Italy tanc Italy

    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=
    
  • 🇮🇳India kaustubhb Mumbai

    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,

  • Status changed to Needs review about 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update about 1 year ago
    424 pass, 2 fail
  • 🇺🇸United States jrb Raleigh-Durham Area, NC, USA

    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.

  • 🇯🇴Jordan n.ghunaim Amman - Jordan

    This patch works with https://www.drupal.org/project/facets/issues/3052574#comment-15155405 🐛 Facets with AJAX not working in most of situations Needs review and D10.

  • 🇯🇴Jordan n.ghunaim Amman - Jordan
  • 🇨🇦Canada maursilveira Windsor, ON

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

  • 🇺🇸United States vlyalko

    this https://www.drupal.org/project/facets/issues/3052574#comment-15155405 🐛 Facets with AJAX not working in most of situations Needs review worked for me

  • Assigned to shubhamsprasad
  • Status changed to RTBC 7 months ago
  • 🇮🇳India shubhamsprasad

    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"
  • Issue was unassigned.
  • Status changed to Needs work 3 months ago
  • 🇺🇸United States lhridley

    Patch / patches in #19 🐛 Facets and exposed filters don't work together with Ajax RTBC 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

Production build 0.71.5 2024