Problem/Motivation

The original issue is here but for the Drupal7 Views module. Below is copy/paste from that issue. All credits to @uq

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.

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.

Hope this helps!

Steps to reproduce

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.

Proposed resolution

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

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

nikita_tt created an issue. See original summary.

nikita_tt’s picture

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.

mwilbur’s picture

Version: 8.9.x-dev » 9.3.x-dev
Component: ajax system » views.module
Status: Active » Needs review
StatusFileSize
new1.73 KB

I ran into a similar problem that patch #2 provided helped with. This issue seems to be present for exposed combined fields filters with no value when applied to a view as well.

Steps I took to reproduce the same issue:

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

The list of results should disappear. I encountered this bug across a couple of different Drupal 9 sites, so I rerolled the patch for 9.3.x

damienmckenna’s picture

Issue tags: -views

Simplifying the tags a little.

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

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mwilbur’s picture

Version: 9.4.x-dev » 9.3.x-dev
StatusFileSize
new2.11 KB

Updating formatting to pass the code quality checks.

ranjith_kumar_k_u’s picture

StatusFileSize
new2.39 KB
new2.63 KB
ranjith_kumar_k_u’s picture

StatusFileSize
new1.46 KB
new2.42 KB
gauravvvv’s picture

StatusFileSize
new1.53 KB
new560 bytes

fixed linting issues in patch, Rerolled patch #9, Attached interdiff for same. please review.

Status: Needs review » Needs work

The last submitted patch, 10: 3100826-10.patch, failed testing. View results

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.

damienmckenna’s picture

Issue tags: +Needs tests

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

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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.

michelle’s picture

StatusFileSize
new1.72 KB

I re-rolled #10 to work on 9.5.1. The only difference seems to be a blank line? Not sure why that made it not apply but this one does.

_utsavsharma’s picture

StatusFileSize
new334 bytes
new1.57 KB

Fixed CCF for 9.5.x in #16.

_utsavsharma’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 16: 3100826-16.patch, failed testing. View results

ilya.no’s picture

Version: 9.5.x-dev » 11.x-dev
StatusFileSize
new827 bytes
new2.06 KB

Attaching patch for the latest version. I haven't succeeded with tests so far, will get back to them later.

gauravvvv’s picture

Status: Needs work » Needs review
StatusFileSize
new818 bytes
new490 bytes

I have fixed the CC failure, attached interdiff for same. please review

Status: Needs review » Needs work

The last submitted patch, 20: 3100826-20.patch, failed testing. View results

ilya.no’s picture

Status: Needs work » Needs review
StatusFileSize
new1.68 KB
new730 bytes

Thanks for the proper update. I've added fix for tests.

smustgrave’s picture

Status: Needs review » Needs work

Believe this still needs a test for the exact problem.

Updating the failing test I don't believe covers the change. &title= is not a default value that I can tell and actually probably shouldn't be in the URL I think if no value is present.

gauravvvv’s picture

ilya.no’s picture

Status: Needs work » Needs review
StatusFileSize
new7.79 KB
new7.23 KB

Attaching patch with new test case.
About &title= part, I've tested following case - I updated 'test_content_ajax' view and switched off AJAX option and checked URLs and this part was presented. So, I assume this as normal behaviour, as non-AJAX view has the same URL.

ilya.no’s picture

StatusFileSize
new8.22 KB
new821 bytes

Sorry for the a bit wrong patch. Attaching proper one.

The last submitted patch, 25: 3100826-25.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 26: 3100826-26.patch, failed testing. View results

ilya.no’s picture

Status: Needs work » Needs review
StatusFileSize
new8.21 KB
new792 bytes

Attaching patch with the fix for tests.

Status: Needs review » Needs work

The last submitted patch, 29: 3100826-29.patch, failed testing. View results

ilya.no’s picture

Status: Needs work » Needs review
StatusFileSize
new8.21 KB
new779 bytes

Fixing wrong function call.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests +Needs Review Queue Initiative, +Bug Smash Initiative

Believe this is ready! Thanks for adding that additional test!

quietone’s picture

Title: Views: AJAX pager doesn't work with exposed filter which has a default value » AJAX pager doesn't work with exposed filter which has a default value
Issue summary: View changes

I'm triaging RTBC issues. I re-read the IS and the comments. I didn't find any unanswered questions. But there is not a failing test to prove the change works.

Reading the patch I have questions about the tests.

  1. +++ b/core/modules/views/tests/src/FunctionalJavascript/PaginationAJAXTest.php
    @@ -46,7 +46,12 @@ protected function setUp(): void {
    +        'title' => $i > 6 ? 'Node ' . $i . ' content' : 'Node ' . $i . ' content default_value',
    

    This is changing the source for the current tests for node 7 -> 11. Does this mean we are losing test coverage?

  2. +++ b/core/modules/views/tests/src/FunctionalJavascript/PaginationAJAXTest.php
    @@ -46,7 +46,12 @@ protected function setUp(): void {
    +        'type' => 'page',
    

    Why is this needed?

So the new test is largely a duplicate of the existing one. And it looks like some refactoring could make the differences between the two tests easier to see. But that is probably out of scope. Plus, it is better to fix the bug and have a followup than to hold this up. What would help is a comment in the setup to explain the need for the later nodes to be different.

However, I am not setting this to Needs works. I will leave at RTBC and let another committer make the decision because I don't work with FuncationalJavascript tests.

  • lauriii committed d251a98e on 11.x
    Issue #3100826 by ilya.no, mwilbur, nikita_tt, smustgrave, quietone:...

  • lauriii committed 9c045ead on 10.1.x
    Issue #3100826 by ilya.no, mwilbur, nikita_tt, smustgrave, quietone:...
lauriii’s picture

Version: 11.x-dev » 10.1.x-dev
Status: Reviewed & tested by the community » Fixed

#33.1 I don't think we've lost test coverage, the existing tests have been updated.
#33.2 Fixed on commit.

Committed d251a98 and pushed to 11.x. Also backported to 10.1.x as a non-disruptive bug fix. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.