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, 6 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 1 hour 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 over 1 year ago
  • πŸ‡·πŸ‡΄Romania radubutco

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

  • Status changed to Needs review over 1 year ago
  • last update over 1 year ago
    29,499 pass, 1 fail
  • Status changed to Needs work over 1 year 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)));

Production build 0.71.5 2024