Exposed forms in a block are not currently updated when Ajax filtering is executed

Created on 12 February 2019, about 6 years ago
Updated 28 August 2024, 7 months ago

Currently when using a view with an exposed form in a block with Ajax enabled the form itself is not updated. This mostly has no issues due to the fact that the form for the most part will remain unchanged. It does however cause an inconsistency as when the form is not added in a block it will reload as part of the Ajax request.

This causes some strange behaviours when combined with any module that intends to run alterations on exposed forms (for example: https://www.drupal.org/project/search_api/issues/2378945 ). Where the patch included here works for views without exposed forms, but does not work with exposed forms due to the inconsistency.

My proposal would be to have the views Ajax controller handle both exposed and non exposed forms in the same way.

Feature request
Status

Needs work

Version

11.0 🔥

Component
Views 

Last updated about 15 hours ago

Created by

🇬🇧United Kingdom andy_w

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Status changed to Needs work almost 2 years ago
  • 🇷🇴Romania radubutco

    Re-rolled it against 11.x, also applies on 10.1.x.

  • Status changed to Needs review almost 2 years ago
  • last update almost 2 years ago
    29,499 pass, 1 fail
  • Status changed to Needs work almost 2 years ago
  • 🇺🇸United States smustgrave

    Was previously tagged for tests which still need to happen.

  • First commit to issue fork.
  • First commit to issue fork.
  • Merge request !61063032353 → (Open) created by SimeonKesmev
  • Status changed to Needs review about 1 year ago
  • 🇺🇸United States cobadger

    Re-rolled patch for 10.2.x and added test coverage.

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States smustgrave

    Tests should be added to the MR. But it needs to be cleaned up as there are now a mix of patches and MRs with no explanation or interdiffs between them.

    Also issue summary should follow standard issue template.

  • 🇧🇪Belgium p-neyens

    New patch starting from comment 42 Exposed forms in a block are not currently updated when Ajax filtering is executed Needs work but with adding the missing use.

    Error: Class "Drupal\views\Controller\RenderContext" not found in Drupal\views\Controller\ViewAjaxController->ajaxView() (regel 222 van /var/app/web/core/modules/views/src/Controller/ViewAjaxController.php).
    Error: Class "Drupal\views\Controller\BubbleableMetadata" not found in Drupal\views\Controller\ViewAjaxController->ajaxView()
  • 🇧🇬Bulgaria SimeonKesmev

    There are instances where the form ID can have uniquifying suffix, so here is a change to account for that.
    The whole approach looks fragile to me as in theory there can be multiple blocks on the page.
    Also I have problem with the facets as the parameter "exposed_form_display" does not get attached, as commented in #28. What is the use case for it?

  • 🇺🇦Ukraine khiminrm

    I've fixed bug with empty "exposed_form_display" mentioned in #45

  • 🇺🇦Ukraine khiminrm

    Noticed bug. when after last the patch the exposed filter block has been refreshed - the exposed form is not submitted by Ajax second time - with page reload.

  • 🇺🇦Ukraine khiminrm

    I've improved a little the exposed form selector to be more precise.

  • 🇺🇦Ukraine khiminrm

    And updated selector in javascript in case if there are multiple exposed forms for the same view on one page

  • 🇨🇿Czech Republic David Urban

    I have tested #49 patch with Core 11.1.1 BEF 7.0.5 and Facets 3.0.0. It fixes the issue with Facets not updating after selecting one.

    But it creates another issue in which View Footer and Pagination gets multiplied on every Ajax update. Is there any chance you could have a look at it please?

  • 🇺🇦Ukraine khiminrm

    @david-urban

    I didn't notice such bug, but I haven't not tested on Core 11.x yet.
    Maybe try to check template for the view. It could be that footer and pagination are outside the view's main 'div' wrapper.
    You can check also ViewAjaxController how it replaces content during ajax call so you will have idea what actually is replaced on a page.

    I've another one bug https://www.drupal.org/node/3163299 and those patch conflicts with this one in similar lines of code. Have not tried yet though. Trying to compare both patches. I hope those issue's patch will work for all cases.

  • 🇺🇦Ukraine khiminrm

    When using multiple instances of the exposed form block for the same view on one page, both forms are updated but only for one of them the behaviors are attached. Any ideas how to fix that?

  • 🇺🇦Ukraine khiminrm

    When exposed form in block, all attributes including classes are moved from the form to the block. In the latest patch only form is replaced. It can produce some bugs. For example if using better_exposed_filters and exclude text fields from autosubmit, it will not work after ajax replace of the exposed form https://git.drupalcode.org/project/better_exposed_filters/-/blob/7.0.x/j.... So it would be better to replace block and not only form.
    So we need to improve somehow this:
    $response->addCommand(new ReplaceCommand("form[id^=\"views-exposed-form-$view_id\"]", $this->renderer->render($exposed_form)));

  • 🇬🇧United Kingdom aurora-norris

    After we updated to Drupal 10.3 and PHP 8.3 this patch caused https://www.drupal.org/project/drupal/issues/3350137#comment-15802025 🐛 renderPlain on a node render array causes RuntimeException if the node renders a view programmatically Needs work to occur so I've added back a line to check if the session exists before trying to access it (the session should theoretically always exist so I'm not sure exactly what the problem is).

  • 🇬🇧United Kingdom aurora-norris

    Turns out the bug I encountered was actually in facets so I'm hiding my patch.

  • 🇮🇳India rahulkhandelwal1990 Gurgugram

    After applying patch drupal-exposed_forms_in_block_not_updated_ajax_filtering-3032353-49.patch i am getting duplicate exposed form on page as i am rendering filters as view block.

Production build 0.71.5 2024