Problem/Motivation

Hi Team,

I am not sure if this bug is because of Views or because of Block module, but here is the issue I am facing.

What behavior were you expecting?
- There should be one AJAX hit, and the throbber should go.

What happened instead?
- There were multiple AJAX hits, as many number of exposed forms, that many ajax hits. 2 forms, 2 ajax hits.
- The throbber doesn't go, as it adds multiple throbbers, but remove only one.

I have tried this on a vanilla install, also this is happening on one of my projects I am working on.

Happy to provide any further information and help.

Thanks.

Steps to reproduce

- Create a new view, say a content view and a page display.
- Add filters and expose them (I also exposed sort).
- Enable "Exposed form in block" to Yes
- Enable AJAX.
- Go to blocks page, and then place the block in 2 regions, or any multiple regions.
- Go to the new view and try applying filters.
- Make sure to open the debug tools, to capture the AJAX hits.

Proposed resolution

TBD

Remaining tasks

TBD

User interface changes

TBD

API changes

TBD

Data model changes

TBD

Release notes snippet

TBD

CommentFileSizeAuthor
#65 multiple-ajax-submissions-2876197-64.patch8.11 KBLuke_Nuke
#62 multiple-ajax-submissions-2876197-62.patch4.06 KBLuke_Nuke
#61 multiple-ajax-submissions-2876197-61.patch3 KBLuke_Nuke
#43 views-multiple-exposed-2876197-21.patch657 bytesahed91
#41 multiple-ajax-submissions-2876197-41.patch9.03 KBLuke_Nuke
#39 multiple-ajax-submissions-2876197-40.patch9.18 KBLuke_Nuke
#38 multiple-ajax-submissions-2876197-39-FAIL.patch6.87 KBLuke_Nuke
#37 multiple-ajax-submissions-2876197-37-FAIL.patch7.2 KBLuke_Nuke
#36 multiple-ajax-submissions-2876197-36.patch2.16 KBLuke_Nuke
#35 multiple-ajax-submissions-2876197-35.patch1.85 KBLuke_Nuke
#34 multiple-ajax-submissions-2876197-34.patch1.88 KBLuke_Nuke
#31 multiple-ajax-submissions-2876197-30.patch1.3 KBdk-massive
#28 multiple-ajax-submissions-2876197-28.patch1.38 KBjacobbell84
#22 multiple-ajax-submissions-2876197-22.patch1.29 KBi.bajrai
#19 drupal-views-multiple-exposed-2876197-19.patch784 bytessam.spinoy@gmail.com
#13 drupal-views-multiple-exposed-2876197-13.patch2.08 KBTommyChris
#8 drupal-views-multiple-exposed-2876197-8.patch2.02 KBpiyuesh23
#8 facets-views-ajax-2826449-8.x-alpha9-24.patch18.58 KBpiyuesh23
#6 drupal-views-multiple-exposed-2876197-6.patch729 bytesthelmer
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vaibhavjain created an issue. See original summary.

dawehner’s picture

Interesting, this sounds indeed like a total bug in views.

jibran’s picture

Version: 8.3.2 » 8.3.x-dev
SwapS’s picture

Indeed an issue . Good catch vaibhavjain.

SwapS

Anonymous’s picture

I tested this and I think its more to do with form ID. Multiple forms with the same ID in single html would always have side effects.

thelmer’s picture

I had the samme issue when inserting the same view with an exposed form multiple times.
It seems to be related to the selector used to add the javascript. It uses the id of the exposed form and this id is the same for each instance.
Adding the surrounding forms (unique) id as a context to the jquery selector fixes the problem.

thelmer’s picture

Notice, that my patch in #6 don't work with exposed forms inserted as blocks outside the view dom.

We will need a fix that either :

- only use the context if the exposed form is not placed with a block
- change the form id to a class and update the selector in the javascript to use this

piyuesh23’s picture

We can make selectors contextual by exposing the block ids via block alter via drupalSettings & using the same in ajax_views.js . Adding a patch for 8.3.x here.

piyuesh23’s picture

Apologies, Patch #1 uploaded accidentally. Was meant for facets module.

The last submitted patch, 8: facets-views-ajax-2826449-8.x-alpha9-24.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 8: drupal-views-multiple-exposed-2876197-8.patch, failed testing. View results

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

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

TommyChris’s picture

Reroll the patch for 8.4.0

borisson_’s picture

Status: Needs work » Needs review

Setting to needs review so that the testbot can pick this patch up.

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Ajax, +views exposed filters

Just tested with Drupal 8.4 and #13 solves the issue.

xjm’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests, +Needs subsystem maintainer review

Thanks for working on this issue! There are a couple of things we need in order commit this fix:

  1. I'm wondering if there's a particular reason we have to attach this build information in hook_block_view_alter(), rather than in the block class itself in /core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php? Tagging for subsystem maintainer review for feedback on the solution.
  2. We need to add an automated test for this bug that fails without the fix, and passes when combined with the fix. We can probably extend core/modules/views/tests/src/FunctionalJavascript/ExposedFilterAJAXTest.php for that.
  3. It looks like this patch only has the ES5 javascript file. Instead of changing /core/modules/views/js/ajax_view.js, we should change /core/modules/views/js/ajax_view.es6.js, and ajax_view.js should be auto-generated from it. See the change record about ES6 for more information. The JS will probably also need a few changes to comply with the AirBnB coding standards. See #2912962: Step 1 JS codestyle: [meta] Fix JS coding standards in core for more information on checking the ES6 file against the standard.

Thanks!

tim.plunkett’s picture

I agree with #16.1, this should be added to \Drupal\views\Plugin\Block\ViewsExposedFilterBlock::build()

sam.spinoy@gmail.com’s picture

Tested patch in #13, it actually broke my setup. I have a view with exposed filters and Ajax enabled, it broke the Ajax part. Page with view on just reloads with url parameters when clicking a filter.

sam.spinoy@gmail.com’s picture

Rerolled thelmer's patch for 8.4.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

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

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

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

i.bajrai’s picture

I have tested this on a page with multiple exposed filters in different parts of the DOM.

I believe its a relatively simple fix and just an oversight TBH.

pnagornyak’s picture

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

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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.

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.

nod_’s picture

Issue tags: +JavaScript

consolidating issues under the JavaScript tag

pcambra’s picture

Status: Needs work » Needs review

Setting to review as patch in #22 doesn't apply for the feedback on #16

jacobbell84’s picture

Quick reroll so the patch applies on 9.2

apaderno’s picture

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

On Drupal 8.9.x, only security issues are fixed.

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

Drupal 9.1.10 (June 4, 2021) and Drupal 9.2.10 (November 24, 2021) were the last bugfix releases of those minor version series. Drupal 9 bug reports should be targeted for the 9.3.x-dev branch from now on, and new development or disruptive changes should 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.

dk-massive’s picture

Rerolled the patch to apply to 9.3

Status: Needs review » Needs work

The last submitted patch, 31: multiple-ajax-submissions-2876197-30.patch, failed testing. View results

apaderno’s picture

Version: 9.3.x-dev » 9.4.x-dev
Luke_Nuke’s picture

Patch updated for 9.4 .

I wonder how we should test this though. Ideally we should be able to detect multiple requests in a functional JS test, but can it be even done in Drupal's testing framework?

Luke_Nuke’s picture

Whoops, wrong patch. This one follows Drupal's js practices and building process.

Luke_Nuke’s picture

Luke_Nuke’s picture

Alright, this is my attempt at testing for this issue. I'm not sure if that's the best way of doing that, but it's something.

Luke_Nuke’s picture

And again a patch issue -_- . Here is the correct one.

Luke_Nuke’s picture

And here is the complete solution.

The last submitted patch, 38: multiple-ajax-submissions-2876197-39-FAIL.patch, failed testing. View results

Luke_Nuke’s picture

I think the previous error was caused by my IDE adding EOL at the end of the file, where it shouldn't be. Let's hope we will finally get it working.

Luke_Nuke’s picture

ahed91’s picture

poker10’s picture

This issue is for Drupal 9 core views module. If you would like to patch Views module for Drupal 7, please create an issue in the Views issues queue here: https://www.drupal.org/project/views

Reverting version.

sneha_surve’s picture

patch #41 works for me on Drupal 9.3.13

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.

Johan den Hollander’s picture

Also happy with the #41 patch as it fixes my double throbber trouble.

rondog469’s picture

patch #41 is also working for me on 9.4.5. I was wondering why my search was getting progressively slower and the throbber wasn't disappearing.

kazah’s picture

NOT WORKING (patch #41) on 9.4

kazah’s picture

Status: Needs review » Active
nod_’s picture

Status: Active » Needs work

Is there is a patch but it's not addressing the issue, the status to set is needs work :)

Luke_Nuke’s picture

@kazah
Me, @rondog469 and tests confirmed that this patch works on Drupal 9.4. Could you please describe the steps you followed to get your result? Could anyone else chime in?

kazah’s picture

After applying patch #41 ajax throbber not disappear the same as in comment #48

kazah’s picture

I am using better exposed filters module with ajax enabled option.
Still have two ajax throbbers, after click apply first throbber dissapear the second still exist.

kazah’s picture

Also I found that barrio theme use button as submit element not input.

rondog469’s picture

I am using bs5 theme and submit button is an input. The patch looks like it takes into account if its a button or input

kazah’s picture

Ok, it works in bartik theme.
But for some reason it doesn't work it barrio theme...

Luke_Nuke’s picture

@kazah
Does barrio's button have type="submit" attribute?

kazah’s picture

Thank you all! Now it works.

Barrio theme rewrites ajax_view.js

I delete these lines in bootstrap_barrio.info.yml

  views/views.ajax:
    - bootstrap_barrio/views.ajax
Luke_Nuke’s picture

Status: Needs work » Needs review

Good to hear that you managed to solve it. It means that barrio needs to port this change to its ajax_views.js to have it fixed. I'm switching back to the Needs review status. I hope we can get RTBC soon.

Luke_Nuke’s picture

I also made a patch for Drupal 10.

Luke_Nuke’s picture

Forgot to run phpcs, so here is the patch with fixed styling issues.

The last submitted patch, 61: multiple-ajax-submissions-2876197-61.patch, failed testing. View results

apaderno’s picture

Status: Needs review » Needs work
Luke_Nuke’s picture

I see what went wrong with D10 patch. Attempt at fixing it.

Luke_Nuke’s picture

Status: Needs work » Needs review

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.

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: -Needs tests +Needs Review Queue Initiative, +Needs issue summary update

This could use an issue summary. Started it but someone familiar with the issue should fill in

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.