Problem/Motivation

When view has ajax on and page url has some parameters what are exposed filters (view page with some applied filter values) if uncheck selected filters and submit exposed form looks view is still filtered by the value from url.

Steps to reproduce

  1. Enable AJAX on the /admin/content view.
  2. Browse to /admin/content?title=&type=All&status=All
  3. Click on the Filter button.
  4. Inspect the AJAX request, the title, type and status GET parameters are duplicated.

Proposed resolution

Get parameters corresponding to filters should be removed from the URL before adding the new ones.

Remaining tasks

Review

User interface changes

NA

Introduced terminology

NA

API changes

NA

Data model changes

NA

Release notes snippet

NA

Issue fork drupal-3121172

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

myha created an issue. See original summary.

myha’s picture

StatusFileSize
new1.03 KB

Here is my solution to fix this: check query url parameters and remove from there all exposed filter parameters because them should be passed in POST parameters.

cilefen’s picture

Status: Active » Needs review

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

mupsi’s picture

StatusFileSize
new1.05 KB

Hey, here is an update of myha's patch for 8.9.x. It works for me, thanks!

ironsizide’s picture

The patch in #5 works well for me.

aaronbauman’s picture

Status: Needs review » Reviewed & tested by the community

LGTM

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

This needs some test coverage.

the.tai.pen@gmail.com’s picture

I had the same issue and patch #5 solved it for me.

greenskin’s picture

Functionality LGTM.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

claudiu.cristea’s picture

Version: 9.2.x-dev » 9.4.x-dev
Issue tags: +Needs usability review

Yes, #5 seems to do it. However, after submitting an exposed filter change, I see the views results and exposed filter being out-of-sync with the URL displayed in browser. Shouldn't JS update also the URL in the browser's address bar? For instance, I'm doing a filtering using the exposed form, then I want to share this search with a colleague but I'm sending them a wrong URL. Maybe this needs some usability input? I'm tagging with "Needs usability review" to get some guidance on the expected behavior.

claudiu.cristea’s picture

Issue tags: -Needs usability review

Tried to write a test but I cannot replicate the error. @myha, could provide steps to replicate the bug as a test?

However, I still need #12. I'll move that part to #343535: Enable bookmarking of AJAX views

rajab natshah’s picture

StatusFileSize
new1.05 KB
new1.05 KB

Updated the patch to work with Drupal 9.3.x and 9.4.x
Only for the process of upgrading from Drupal 8 to Drupal 9

ravi.shankar’s picture

StatusFileSize
new1.05 KB
new751 bytes

Fixed Drupal CS issue of patch #15.

prudloff’s picture

StatusFileSize
new505 bytes
new1.15 KB

I have a similar issue but with pages. If the page query parameter is set, then it is used in ViewAjaxController even though it is not in the POST data.
This creates weird behaviors, for example sending users to a page that does not exist for the current set of selected exposed filters.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

pasqualle’s picture

Thanks for the patch. Works great.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

aaronbauman’s picture

Status: Needs work » Needs review
StatusFileSize
new1.23 KB

None of these patches work against drupal ^10.1 or ^11

Here's a re-roll

aaronbauman’s picture

StatusFileSize
new1.22 KB

And fix the path

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Was previously tagged for tests which still appear to be needed.

And issue summary could use some attention.

Thanks

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

prudloff’s picture

This patch seems to break #343535: Enable bookmarking of AJAX views when both are applied.

AaronBauman changed the visibility of the branch 3121172-exposed-filters-url to hidden.

aaronbauman’s picture

StatusFileSize
new1.23 KB

Re-rolled against 11.x and 10.2.x

Still working for me, still needs tests

hiding MR 1484 to minimize noise, but please unhide if someone wants to untangle it.

akalam’s picture

StatusFileSize
new632 bytes

Patch on #28 didn't work for me using facets v3.

I'm uploading a new patch using a simpler solution, skip url querystring on the settings object being passed to the ajax method on javascript. By this way, all the input from the form is being sent, but the querystring is not, so no override on parameters is raising the server.

joaopauloc.dev’s picture

patch #29 worked for me, Drupal 10.2.6 thanks!

unstatu’s picture

StatusFileSize
new1.55 KB

I have improved the approach taken by #29 in order to only remove the inputs existing in the exposed form from the URL used by AJAX.

I did this because I found a problem using the media library with this patch applied. The steps to reproduce the problem are the following :

- Open the media library modal of a field widget
- Use the exposed form in the media library modal and send the form to filter the results
- Select any media and click insert
- You will get the following error: "The opener ID parameter is required and must be a string."

This happens because the patch in #29 is removing the query parameters required by the media library (in addition to the ones present in the exposed form) when the AJAX call is done.

unstatu’s picture

StatusFileSize
new1.57 KB

I messed up with the paths.

This version has the same code but with the correct paths.

akalam’s picture

StatusFileSize
new1.57 KB
new524 bytes

Patch #32 is using "this" instead of "that" in a context where this is the windows object. Here's a patch fixing it

gun_dose’s picture

StatusFileSize
new1.83 KB

Patch #33 has some issues for me. It operates with form values, so if I have some value in URL, uncheck it, apply filters and then check other value, both values appears checked, because form data doesn't contain value key if all options are unchecked. Also in my case I have multiple values for my filter, so in URL it appears as manufacturer[0], manufacturer[1] etc. And in form adata it appearc as manufacturer[] (with empty brakes). To handle this I splitted filter names by openig square brake and now it works for me.

andreic’s picture

The only patch version that works for me in 10.2.6 was the one in #34. However, it fixes only the tag filtering, those are respected now but the problem is results are no longer returned.

gordonio’s picture

I ran into the same issue as #31 with the opener_id error when trying to use media library items after using the views exposed filters to search for something. The patch in #34 seems to be working fine for me and I haven't noticed any issues with filtering so far.

Core Version 10.2.6

prudloff changed the visibility of the branch 10.0.x to hidden.

prudloff changed the visibility of the branch 11.x to hidden.

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

ironnuts’s picture

Tried to fix Javascript lint. Search and replaced $exposed_form with camelcase $exposedForm. Reduced lint errors from 20 to 18.

niranjan_panem’s picture

Tested it in drupal 11 with below description.

1. created a view
2. created the filter of authored on field and exposed it
3. tested the filter field with before adding ajax to exposed form.
4. tested the filter field with after adding ajax to exposed form.

Before adding ajax, filter parameters are taken from url and giving expected output.
After adding ajax, filter parameters which still exist in url are not taken to get results.

It is working as expected.

Below is the screen shot of before adding ajax.

screen shot of before adding ajax

Below is the screen shot of after adding ajax.

screen shot of after adding ajax

prudloff’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

This will get more visible if #343535: Enable bookmarking of AJAX views is merged, because then a lot more AJAX requests will be made with existing GET parameters in the URL.
I will try to find a way to show this in a test.

prudloff’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
Related issues: +#343535: Enable bookmarking of AJAX views

I added a test that shows the problem.

prudloff’s picture

I tried reverting the camel case changes locally but it makes yarn run lint:core-js-passing complain:

/media/pierre/Projets/workspace/drupal-core/core/modules/views/js/ajax_view.js
  176:20  error  Identifier '$exposed_form' is not in camel case  camelcase
  182:5   error  Insert `··`                                      prettier/prettier
  182:5   error  Identifier '$exposed_form' is not in camel case  camelcase

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Hiding patches and closing old MRs

Following the steps I get a request like

https://drupal-11x.ddev.site/views/ajax?status=All&title=&type=All&_wrapper_format=drupal_ajax&title=&type=All&status=All&view_name=content&view_display_id=page_1&view_args=&view_path=%2Fadmin%2Fcontent&view_base_path=admin%2Fcontent&view_dom_id=163f73bb84d4e170f0b939de25d6c337ec0daf0d5e472897f73c099a6e1eb94f&pager_element=0&_drupal_ajax=1&ajax_page_state%5Btheme%5D=claro&ajax_page_state%5Btheme_token%5D=U8_NBi2POrE9U1ELs8h7ziadng1Svy8k__iIvXtLat0&ajax_page_state%5Blibraries%5D=eJx9j20OwjAIhi_UbWfwJIZ2ZKuy0gCdH6e36hqjS_zTwMMDeevjdMwx4-C3wgUC4WGUkoH6BGtn4HWjE7EH6tRuFNPkAifDqxWg5n9IV42z_leMmTxIlQTbGILFFV_bX7ymIJwRRpQ9F9TMSevifqZIGOzNE8sCFO_odGaxUKyprXdbpqFl--l71AAZD-MSkyuK0g486z7Wz6lbI150eL09nOD6BRYeC-EDDheR7w

After applying the MR

I get

https://drupal-11x.ddev.site/views/ajax?_wrapper_format=drupal_ajax&title=&type=All&status=All&view_name=content&view_display_id=page_1&view_args=&view_path=%2Fadmin%2Fcontent&view_base_path=admin%2Fcontent&view_dom_id=6bd75558a30df1be7b7f74ebc9fc473a68a2dc3c5e496a831679f7aed2d7155a&pager_element=0&_drupal_ajax=1&ajax_page_state%5Btheme%5D=claro&ajax_page_state%5Btheme_token%5D=U8_NBi2POrE9U1ELs8h7ziadng1Svy8k__iIvXtLat0&ajax_page_state%5Blibraries%5D=eJx9j20OwjAIhi_UbWfwJIZ2ZKuy0gCdH6e36hqjS_zTwMMDeevjdMwx4-C3wgUC4WGUkoH6BGtn4HWjE7EH6tRuFNPkAifDqxWg5n9IV42z_leMmTxIlQTbGILFFV_bX7ymIJwRRpQ9F9TMSevifqZIGOzNE8sCFO_odGaxUKyprXdbpqFl--l71AAZD-MSkyuK0g486z7Wz6lbI150eL09nOD6BRYeC-EDDheR7w

Not the best with nightwatch review and test-only pipeline doesn't work with nightwatch But

browser.assert.strictEqual(
              url.searchParams.getAll('title').length,
              1,
              'Duplicate title parameter',
            );

Should show the duplicates so believe it's valid coverage

Going to mark.

nod_’s picture

Status: Reviewed & tested by the community » Needs work

had a comment on the MR waiting for several weeks, sorry about that

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

carolpettirossi’s picture

StatusFileSize
new438.66 KB
new698.25 KB

This issue also manifests in the Media Library modal when using exposed filters with multi-value select fields (e.g. a folder/directory filter).
Steps to reproduce with Media Library:

  1. Open a Media Library modal via a field widget (e.g. an image field on a node edit form)
  2. Use an exposed filter with a select[multiple] element to filter results
  3. Change the selection and apply filters again
  4. Inspect the AJAX request — filter values from previous selections are duplicated in the payload

What happens in the payload:
The directory[] filter values were being sent three times - once from the accumulated URL query string embedded in view_query, once from the serialized form data, and then the new selection appended at the end. The result was that old selections were never cleared.

Before and After patch videos attaches for reference.

Confirmed working on Drupal 10.5.6 with the Media Library widget.

prudloff’s picture

Status: Needs work » Needs review

Now that #343535: Enable bookmarking of AJAX views has been committed, this bug basically breaks AJAX exposed filters after the first submit so we should really get this fixed.

smustgrave’s picture

Fact some tests had to be updated to pass makes me worried this will be a BC for contrib tests.

prudloff’s picture

The order of the parameters in PaginationAJAXTest was changed by #343535: Enable bookmarking of AJAX views: https://git.drupalcode.org/project/drupal/-/commit/9c8eb293cae3114a76b95...
This MR reverts to the previous order. (It is a side effect, but you could say it fixes the BC break from #343535: Enable bookmarking of AJAX views.)

smustgrave’s picture

Status: Needs review » Needs work

Good to know! Left a comment on the test though.

smustgrave’s picture

Maybe a test in ExposedFilterAJAXTest can be expanded?

mialdi98’s picture

Rolling patch (without tests) for Drupal 11.3 if someone is updating their site and getting composer errors

from https://git.drupalcode.org/project/drupal/-/merge_requests/10230/diffs (#34)

acbramley’s picture