Problem/Motivation

On a page with multiple ajax buttons, clicking one button causes all the buttons on the page to spin/throb, but should only cause the clicked one to spin. The extra throbbers that appear do not disappear.

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

Update the code so that only the clicked button generates a throbber. Other ajax buttons should not be affected.

Remaining tasks

n/a

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Release notes snippet

n/a

Original report

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.

Issue fork drupal-2876197

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

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

StatusFileSize
new729 bytes

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

Status: Active » Needs review
StatusFileSize
new18.58 KB
new2.02 KB

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()

Anonymous’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.

Anonymous’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

StatusFileSize
new1.29 KB

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

StatusFileSize
new1.38 KB

Quick reroll so the patch applies on 9.2

avpaderno’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

avpaderno’s picture

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

StatusFileSize
new1.88 KB

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

StatusFileSize
new1.85 KB

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

luke_nuke’s picture

StatusFileSize
new2.16 KB

Let's try again.

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

StatusFileSize
new6.87 KB

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

luke_nuke’s picture

Status: Needs work » Needs review
StatusFileSize
new9.18 KB

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

StatusFileSize
new9.03 KB

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

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

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

StatusFileSize
new4.06 KB

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

avpaderno’s picture

Status: Needs review » Needs work
luke_nuke’s picture

StatusFileSize
new8.11 KB

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.

danny englander’s picture

Issue tags: -JavaScript +JavaScript

I tested the patch in #65 and it applies and works fine with Drupal 10.2.5. My use case is that I want different parts of the same exposed Ajax form in 2 areas of the page. This works as expected, no log errors, no console errors, or Ajax errors.

Something that baffles me is the form ids are duplicated for each implementation of the exposed form. There are a number of issues open for that, a few in the "Related" and "Referenced by" section on this page. I always understood that duplicate form ids were not good for accessibility and could cause unexpected issues so just wanted to flag that with this patch.

charlliequadros’s picture

StatusFileSize
new8.16 KB

This patch was modified to work with Drupal 10.3.6.

gauravjeet’s picture

It's been a while this issue is opened and the patches (re-rolls) apply and work succesfully, can this be merged into core now or, are there any other pressing issues stopping this patch merge?

Patch #71 works fine for me btw!

nicrodgers’s picture

Title: Views multiple exposed form, Ajax enabled, multiple ajax hits on submit » On a page with multiple Views exposed Ajax enabled forms, multiple throbbers appear on submit
Issue summary: View changes
Issue tags: -JavaScript, -Needs issue summary update +JavaScript

nicrodgers’s picture

Status: Needs work » Needs review
Issue tags: -JavaScript +JavaScript

I've updated the issue summary, and created a merge request based on the patch from #71 as the patches have been deprecated.

nicrodgers’s picture

Status: Needs review » Needs work

Setting back to needs work due to the failing coding standards issues picked up in the pipeline.

xjm’s picture

Amending attribution.

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

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

prudloff’s picture

I fixed code style problems but now some unit test is failing.

jeroent’s picture

Status: Needs work » Needs review

I fixed the failing tests.
There are still some tests failing on PHP 8.5, but I see the same failurs on the 11.2.x branch:
https://git.drupalcode.org/project/drupal/-/pipelines/614551

So I think those are not related tot his issue.

smustgrave’s picture

Status: Needs review » Needs work

Seems this may need a manual rebase.

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.

prudloff’s picture

Status: Needs work » Needs review

I merged the latest main and fixed a deprecation.

sachin patel’s picture

oily’s picture

Ran the TEST-ONLY test:

https://git.drupalcode.org/issue/drupal-2876197/-/jobs/8938220

There is one test failure relating to the assertion at line 121 of the test. Test coverage LGTM.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new667 bytes

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.