Robustify how ajax finds the facet block

Created on 15 November 2018, over 6 years ago
Updated 20 January 2023, over 2 years ago

Improvements needed:

  1. Cleanup Drupal attached so that views dom id and paths are not enclosed in functions.
  2. Support nested views. Use case: A views area in the "No results" / empty view section.
  3. Track if a view's dom id has changed on the page as a result from other AJAX refreshes (example pagers).
✨ Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States recrit

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

Merge Requests

Comments & Activities

Not all content is available!

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

  • πŸ‡§πŸ‡¬Bulgaria ovanes Sofia
  • πŸ‡³πŸ‡±Netherlands gaele

    If I try patch #40 with 2.0.6 the filters work correctly but no longer use Ajax, i.e. the whole page is refreshed.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    424 pass, 2 fail
  • πŸ‡ΊπŸ‡ΈUnited States recrit

    The attached patch has the following updates:

    • Removed jQuery.once(). This is no longer available in D10+.
    • Updated selector that finds the views exposed FORM element. This adds support for multiple exposed forms for the same Views display on the same page. See http://drupal.org/node/2894747
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    424 pass, 2 fail
  • πŸ‡ΊπŸ‡ΈUnited States recrit

    some whitespace cleanup

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    424 pass, 2 fail
  • πŸ‡ͺπŸ‡ΈSpain pcambra Asturies

    #44 is working great, I had some issues with the facet settings being empty when adding more facets that are not sliders, I think checking for an object is safer.

  • πŸ‡ΊπŸ‡ΈUnited States recrit

    The test failures are caused by the view_id and display_id bleeding into the URL query parameters.

    --- Expected
    +++ Actual
    @@ @@
    -'route:view.search_api_test_view.page_1;arg_0&arg_1&arg_2?f%5B0%5D=owl%3Afuzzy'
    +'route:view.search_api_test_view.page_1;arg_0&arg_1&arg_2&view_id=search_api_test_view&display_id=page_1?f%5B0%5D=owl%3Afuzzy'
    
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    424 pass, 2 fail
  • πŸ‡ΊπŸ‡ΈUnited States recrit

    This updated patch only parses the query string when there is a query string. This fixes views adding an extra query parameter with the full href as the property name.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ͺπŸ‡ΈSpain pcambra Asturies

    Found an issue probably related to πŸ› Ajax Facets do not support Range Slider Needs review , the slider themselves work fine, but they do remove and override the search query from other facets and exposed filters (this is not the behavior from other facet types after this patch)

  • πŸ‡ΊπŸ‡ΈUnited States recrit

    @pcambra do you mean that slider does not work correctly after patch #47, #45 or both?

  • πŸ‡ͺπŸ‡ΈSpain pcambra Asturies

    @recrit both but I think it a more deep issue than the latest fixes, there's a bit of code after "// Update view on slider trigger." that takes care of updating the view and that refresh works correctly but both the url and the other facets get deselected/emptied.

  • πŸ‡ͺπŸ‡ΈSpain pcambra Asturies
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    424 pass, 2 fail
  • πŸ‡ͺπŸ‡ΈSpain pcambra Asturies

    Minor changes above that I've been testing, we don't need to update 2x if we're on a slider, and I've been adding improvements to the slider.js on ✨ Range slider should use javascript events Needs review so it actually refreshes with ajax.

    However, we still have the issue that everything else is lost when refreshing the slider with ajax (it loses context), and that's where the idea on πŸ› Ajax Facets do not support Range Slider Needs review although a bit crafty, fixes the issue caused by blindly retrieving the href from the settings:

    var href = settings.facets.sliders[facetId].url.replace('__range_slider_min__', ui.values[0]).replace('__range_slider_max__', ui.values[1]);

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    424 pass, 2 fail
  • πŸ‡ΊπŸ‡ΈUnited States recrit

    I do not have any sliders enabled on my search pages which is resulting in this error:

    Uncaught TypeError: settings.facets.sliders is undefined
    

    I updated the check for typeof settings.facets.sliders[facetId] !== 'object' to also check for its existence.

  • πŸ‡ͺπŸ‡ΈSpain pcambra Asturies

    @recrit: thanks! do you think that it would be a better fit to instead of taking care of possible sliders, launch an event that each widget could subscribe to refresh the views? seems to me that there's a lot of code on this ajax views file atm and some of them makes no sense if you don't have the slider submodule enabled.

  • πŸ‡ΊπŸ‡ΈUnited States recrit

    @pcambra An event would be good. That would let other contrib modules and custom code to react to the changes as well.

  • πŸ‡ͺπŸ‡ΈSpain pcambra Asturies
  • πŸ‡ΊπŸ‡ΈUnited States recrit

    the attached patch adds the following:
    - AJAX controller updates only from πŸ› Facets with AJAX not working in most of situations Needs work to properly set the session on the new request. The other changes in 3052574 conflict with this patch since it is trying to fix the JS and change how the blocks are rendered in the AJAX controller.

    - AJAX controller updates from πŸ› New $request created in FacetBlockAjaxController missing ajax_page_state RTBC to persist the "ajax_page_state".

  • πŸ‡«πŸ‡·France Renrhaf πŸ“ Strasbourg 🐦🦜

    +1

  • πŸ‡§πŸ‡ΎBelarus VasiliyRepin Minsk

    #57 I have been tested this patch. It works good for my tasks! Thanks!

  • πŸ‡§πŸ‡ΎBelarus VasiliyRepin Minsk

    For using in ajax Views perfect Slider better than Ui - Facets range NoUiSlider β†’
    you need to apply #57 and after need to apply this patch.

  • πŸ‡§πŸ‡ΎBelarus VasiliyRepin Minsk

    #57 doesn't work with new versions (2.0.9+)

  • πŸ‡¨πŸ‡¦Canada Liam Morland Ontario, CA πŸ‡¨πŸ‡¦

    liam morland β†’ made their first commit to this issue’s fork.

  • πŸ‡¨πŸ‡¦Canada Liam Morland Ontario, CA πŸ‡¨πŸ‡¦

    Patch 57 ported to 2.0.x. Not tested.

  • Pipeline finished with Success
    about 2 months ago
    Total: 871s
    #434080
  • πŸ‡ͺπŸ‡ΈSpain eduardo morales alberti Spain, πŸ‡ͺπŸ‡Ί

    Patch #57 working on (2.0.9)
    Patches applied:

                "drupal/facets": {
                    "Facets with AJAX not working in most of situations - https://www.drupal.org/i/3052574": "patches/facets-ajax-fix-3052574-2.0.9.patch",
                    "Disable updating the facets after each facet selection for Apply/Reset facet buttons block - https://www.drupal.org/i/3172373": "patches/facets-disable-auto-refresh-3172373-12_rerroll_206.patch",
                    "Ajax facet block seems to lose Views context - https://www.drupal.org/i/2986981": "patches/facets-ajax-views-context-2986981-42.patch",
                    "New $request created in FacetBlockAjaxController missing ajax_page_state - https://www.drupal.org/i/3466566": "https://www.drupal.org/files/issues/2024-08-20/facets-add-missing-ajax_page_state-3466566-2.0.8.patch",
                    "Robustify how ajax finds the facet block - https://www.drupal.org/i/3013795": "patches/facets-ajax-improvements-3013795-56--ajax-controller-updates-from-3052574-3466566-reroll.patch"
                },
    

    Last error solved:

    Uncaught TypeError: Cannot read properties of undefined (reading 'settings')
        at updateFacetsView (js_VxN4_hEWvDkJM9zlGIezKjTLVZVJYA-B7R6DZGFUNt4.js?scope=footer&delta=0&language=en&theme=custom_radix&include=eJxti0EOgCAMBD8E8iTSQKvVBk2LwvNNIN487swsQcJqIet9gSw01iJcDt84r1gd_QUPYzMPO3RnaQPUqJC5h6nd0JELceGK0ZKeImGePuonfQFvgjHg&exclude=eJyNUkFywyAM_BCGX_QD6Z0RWLZJZZSCcOPfByduYqfJTC9i2d0ZoRVwhLMlhhaTgQfWMiR2DpOCKMGxmPXUHadReQoYJYcW7QQUWpDA0R6_C6bZ-EnfkA4d_te6aqh65p7QCvSmr-X5rpdH7slRZT8AJlurmA3WkeGuvXqGWSGn_PAVZzZYey5RUsC7owtI7dLaZpkJzeFKfyzsJ_SHhfu1RvzJhCI12z-MrX2BYK4Rr1qCNpxNT-yA3qkDLtvZcyPG0hBOSE2u4-ALdYQQ9_QpcVu8NA5Sw12XUfZ6RkIvtqvfQULsLYFDerJsR80IyQ_mdmwiVisDp2ChCHseTzUANG94lecsOBoHGdUUalzmWm973xJjHaD2n7lIcWg981fdkuGIkkqWC-WOHrA:4:3185)
        at HTMLUListElement.<anonymous> (js_VxN4_hEWvDkJM9zlGIezKjTLVZVJYA-B7R6DZGFUNt4.js?scope=footer&delta=0&language=en&theme=custom_radix&include=eJxti0EOgCAMBD8E8iTSQKvVBk2LwvNNIN487swsQcJqIet9gSw01iJcDt84r1gd_QUPYzMPO3RnaQPUqJC5h6nd0JELceGK0ZKeImGePuonfQFvgjHg&exclude=eJyNUkFywyAM_BCGX_QD6Z0RWLZJZZSCcOPfByduYqfJTC9i2d0ZoRVwhLMlhhaTgQfWMiR2DpOCKMGxmPXUHadReQoYJYcW7QQUWpDA0R6_C6bZ-EnfkA4d_te6aqh65p7QCvSmr-X5rpdH7slRZT8AJlurmA3WkeGuvXqGWSGn_PAVZzZYey5RUsC7owtI7dLaZpkJzeFKfyzsJ_SHhfu1RvzJhCI12z-MrX2BYK4Rr1qCNpxNT-yA3qkDLtvZcyPG0hBOSE2u4-ALdYQQ9_QpcVu8NA5Sw12XUfZ6RkIvtqvfQULsLYFDerJsR80IyQ_mdmwiVisDp2ChCHseTzUANG94lecsOBoHGdUUalzmWm973xJjHaD2n7lIcWg981fdkuGIkkqWC-WOHrA:4:2844)
        at HTMLUListElement.dispatch (js_v4R1nHEnukJUV1bLoiDZZc0YO5ablXaBNbuEfNdemn4.js?scope=footer&delta=0&language=en&theme=custom_radix&include=eJyNUkFywyAM_JANv-gH0jsjsIxJZZSCcOPfByduYqfJTC_SsrszoBVwhLMhhg6ThgdWMiS2FlMDUYJl0WtXPaexcRQwSg4dmgkodCCBozl-F0yzdpO6IRV6_K911bDxzJ7QCHjta3k-q-WRe3JsshsAk6lV9AaryHDXXj1Dr5BTfviK1RusHJcoKeDd0QekbrnaZJkJ9eFKfyzsJ_jDwv1aI_5kQpGa7R_G1HuBYK4Rr1qCLpy1J7ZA79QBl-3suRFjaQknpDbXcfCFOkKIe_qUuCtOWgup5b7PKHs9I6ET09fvICF6Q2CRnizbUTNCcoO-tU3EzcrAKRgowo7HUw0A9Ru-mUKNSF_rbdczFykWjWP-qmvQHFFSyXIB9ZsSqg:3:40035)
        at v.handle (js_v4R1nHEnukJUV1bLoiDZZc0YO5ablXaBNbuEfNdemn4.js?scope=footer&delta=0&language=en&theme=custom_radix&include=eJyNUkFywyAM_JANv-gH0jsjsIxJZZSCcOPfByduYqfJTC_SsrszoBVwhLMhhg6ThgdWMiS2FlMDUYJl0WtXPaexcRQwSg4dmgkodCCBozl-F0yzdpO6IRV6_K911bDxzJ7QCHjta3k-q-WRe3JsshsAk6lV9AaryHDXXj1Dr5BTfviK1RusHJcoKeDd0QekbrnaZJkJ9eFKfyzsJ_jDwv1aI_5kQpGa7R_G1HuBYK4Rr1qCLpy1J7ZA79QBl-3suRFjaQknpDbXcfCFOkKIe_qUuCtOWgup5b7PKHs9I6ET09fvICF6Q2CRnizbUTNCcoO-tU3EzcrAKRgowo7HUw0A9Ru-mUKNSF_rbdczFykWjWP-qmvQHFFSyXIB9ZsSqg:3:38006)
        at Object.trigger (js_v4R1nHEnukJUV1bLoiDZZc0YO5ablXaBNbuEfNdemn4.js?scope=footer&delta=0&language=en&theme=custom_radix&include=eJyNUkFywyAM_JANv-gH0jsjsIxJZZSCcOPfByduYqfJTC_SsrszoBVwhLMhhg6ThgdWMiS2FlMDUYJl0WtXPaexcRQwSg4dmgkodCCBozl-F0yzdpO6IRV6_K911bDxzJ7QCHjta3k-q-WRe3JsshsAk6lV9AaryHDXXj1Dr5BTfviK1RusHJcoKeDd0QekbrnaZJkJ9eFKfyzsJ_jDwv1aI_5kQpGa7R_G1HuBYK4Rr1qCLpy1J7ZA79QBl-3suRFjaQknpDbXcfCFOkKIe_qUuCtOWgup5b7PKHs9I6ET09fvICF6Q2CRnizbUTNCcoO-tU3EzcrAKRgowo7HUw0A9Ru-mUKNSF_rbdczFykWjWP-qmvQHFFSyXIB9ZsSqg:3:70124)
        at HTMLUListElement.<anonymous> (js_v4R1nHEnukJUV1bLoiDZZc0YO5ablXaBNbuEfNdemn4.js?scope=footer&delta=0&language=en&theme=custom_radix&include=eJyNUkFywyAM_JANv-gH0jsjsIxJZZSCcOPfByduYqfJTC_SsrszoBVwhLMhhg6ThgdWMiS2FlMDUYJl0WtXPaexcRQwSg4dmgkodCCBozl-F0yzdpO6IRV6_K911bDxzJ7QCHjta3k-q-WRe3JsshsAk6lV9AaryHDXXj1Dr5BTfviK1RusHJcoKeDd0QekbrnaZJkJ9eFKfyzsJ_jDwv1aI_5kQpGa7R_G1HuBYK4Rr1qCLpy1J7ZA79QBl-3suRFjaQknpDbXcfCFOkKIe_qUuCtOWgup5b7PKHs9I6ET09fvICF6Q2CRnizbUTNCcoO-tU3EzcrAKRgowo7HUw0A9Ru-mUKNSF_rbdczFykWjWP-qmvQHFFSyXIB9ZsSqg:3:70726)
        at ce.each (js_v4R1nHEnukJUV1bLoiDZZc0YO5ablXaBNbuEfNdemn4.js?scope=footer&delta=0&language=en&theme=custom_radix&include=eJyNUkFywyAM_JANv-gH0jsjsIxJZZSCcOPfByduYqfJTC_SsrszoBVwhLMhhg6ThgdWMiS2FlMDUYJl0WtXPaexcRQwSg4dmgkodCCBozl-F0yzdpO6IRV6_K911bDxzJ7QCHjta3k-q-WRe3JsshsAk6lV9AaryHDXXj1Dr5BTfviK1RusHJcoKeDd0QekbrnaZJkJ9eFKfyzsJ_jDwv1aI_5kQpGa7R_G1HuBYK4Rr1qCLpy1J7ZA79QBl-3suRFjaQknpDbXcfCFOkKIe_qUuCtOWgup5b7PKHs9I6ET09fvICF6Q2CRnizbUTNCcoO-tU3EzcrAKRgowo7HUw0A9Ru-mUKNSF_rbdczFykWjWP-qmvQHFFSyXIB9ZsSqg:3:3129)
        at ce.fn.init.each (js_v4R1nHEnukJUV1bLoiDZZc0YO5ablXaBNbuEfNdemn4.js?scope=footer&delta=0&language=en&theme=custom_radix&include=eJyNUkFywyAM_JANv-gH0jsjsIxJZZSCcOPfByduYqfJTC_SsrszoBVwhLMhhg6ThgdWMiS2FlMDUYJl0WtXPaexcRQwSg4dmgkodCCBozl-F0yzdpO6IRV6_K911bDxzJ7QCHjta3k-q-WRe3JsshsAk6lV9AaryHDXXj1Dr5BTfviK1RusHJcoKeDd0QekbrnaZJkJ9eFKfyzsJ_jDwv1aI_5kQpGa7R_G1HuBYK4Rr1qCLpy1J7ZA79QBl-3suRFjaQknpDbXcfCFOkKIe_qUuCtOWgup5b7PKHs9I6ET09fvICF6Q2CRnizbUTNCcoO-tU3EzcrAKRgowo7HUw0A9Ru-mUKNSF_rbdczFykWjWP-qmvQHFFSyXIB9ZsSqg:3:1594)
        at ce.fn.init.trigger (js_v4R1nHEnukJUV1bLoiDZZc0YO5ablXaBNbuEfNdemn4.js?scope=footer&delta=0&language=en&theme=custom_radix&include=eJyNUkFywyAM_JANv-gH0jsjsIxJZZSCcOPfByduYqfJTC_SsrszoBVwhLMhhg6ThgdWMiS2FlMDUYJl0WtXPaexcRQwSg4dmgkodCCBozl-F0yzdpO6IRV6_K911bDxzJ7QCHjta3k-q-WRe3JsshsAk6lV9AaryHDXXj1Dr5BTfviK1RusHJcoKeDd0QekbrnaZJkJ9eFKfyzsJ_jDwv1aI_5kQpGa7R_G1HuBYK4Rr1qCLpy1J7ZA79QBl-3suRFjaQknpDbXcfCFOkKIe_qUuCtOWgup5b7PKHs9I6ET09fvICF6Q2CRnizbUTNCcoO-tU3EzcrAKRgowo7HUw0A9Ru-mUKNSF_rbdczFykWjWP-qmvQHFFSyXIB9ZsSqg:3:70701)
        at HTMLAnchorElement.clickHandler (js_VxN4_hEWvDkJM9zlGIezKjTLVZVJYA-B7R6DZGFUNt4.js?scope=footer&delta=0&language=en&theme=custom_radix&include=eJxti0EOgCAMBD8E8iTSQKvVBk2LwvNNIN487swsQcJqIet9gSw01iJcDt84r1gd_QUPYzMPO3RnaQPUqJC5h6nd0JELceGK0ZKeImGePuonfQFvgjHg&exclude=eJyNUkFywyAM_BCGX_QD6Z0RWLZJZZSCcOPfByduYqfJTC9i2d0ZoRVwhLMlhhaTgQfWMiR2DpOCKMGxmPXUHadReQoYJYcW7QQUWpDA0R6_C6bZ-EnfkA4d_te6aqh65p7QCvSmr-X5rpdH7slRZT8AJlurmA3WkeGuvXqGWSGn_PAVZzZYey5RUsC7owtI7dLaZpkJzeFKfyzsJ_SHhfu1RvzJhCI12z-MrX2BYK4Rr1qCNpxNT-yA3qkDLtvZcyPG0hBOSE2u4-ALdYQQ9_QpcVu8NA5Sw12XUfZ6RkIvtqvfQULsLYFDerJsR80IyQ_mdmwiVisDp2ChCHseTzUANG94lecsOBoHGdUUalzmWm973xJjHaD2n7lIcWg981fdkuGIkkqWC-WOHrA:3:368)
    
  • πŸ‡΅πŸ‡­Philippines mjgruta

    MR #291 works fine on my end using latest 2.0.x-dev
    Attaching here the MR code to prevent issue if someone wants to update the code.

Production build 0.71.5 2024