Currently when a view uses AJAX pager and exposed filter with a default value at the same time, the view is not providing an accurate result when navigating the page.

To reproduce the issue:
1) Create a content type with a date field
2) Create a number of nodes with above content type
3) Create a View using unformatted list and fields under Format
4) Add Content: [Your date field] under Filter Criteria
5) Select Year under Filter Granularity
6) Check the checkbox "Expose this filter to visitors, allow them to change it" in the Configure filter criterion popup
6) Select a year (e.g. 2014) under Operator
7) Click Apply (all displays)
8) Click Advanced > User AJAX and select Yes
9) Save the view and go to the view page
10) Select "-Year" in the exposed filter and click apply

At this point, you should see a list of nodes with that field and a pager underneath

11) Go to page 2 through the pager

The list of nodes are gone and the exposed filter is reset to the default value.

The issue here was within the javascript of views. If the parameter doesn't have a property or if it is null (in this case, the date value is null after you selected "-Year"), it removes the parameter in the request. If the parameter is removed, Views will set the filter to the default value.

The patch allows empty property to be passed within the query string parameter.

Hope this helps!

Comments

uq created an issue. See original summary.

uq’s picture

Status: Active » Needs review
uq’s picture

jackson.cooper’s picture

Here's a re-rolled patch for Views v3.20.

nikita_tt’s picture

Thanks for the patch!
I've copy/paste this issue for the 8.x Drupal core.

https://www.drupal.org/project/drupal/issues/3100826

nikita_tt’s picture

damienmckenna’s picture

The D9 patch is being used on a large site at work, which gives validation for the solution.

Here are mwilbur's testing instructions:

* Create a Content type and add 10 Nodes.
* Create a View as an unformatted list
* Add a block Display
* Enable Ajax for the view
* Add a combined fields filter that is exposed and searching 2 more fields on the content type
* Set Exposed Filters to be "Input Required"
* Configure the new view block to be visible on the site somewhere and traverse to it
* Apply the exposed filters to the view with no values set so that all results display
* Paginate to the second page
* The list of results will disappear

damienmckenna’s picture

Version: 7.x-3.14 » 7.x-3.x-dev

damienmckenna’s picture

Issue tags: +Needs tests

I think we can add test coverage for this by simulating the request.

joseph.olstad’s picture

The D7 views patch is pretty much identical to the D9 patch, nice.

joseph.olstad’s picture

To write a test for this, one could possibly borrow existing test code from:

tests/handlers/views_handler_filter_string.test

and copy the ajax test in
tests/views_ajax.test

to write a new ajax test for the filter.
combine the two tests together.