Problem/Motivation

If we have views with AJAX enabled, that contains AJAX-forms in results (e.g. commerce AJAX add to cart forms), all forms will not work after view was updated. Reason is form action, that becomes 'views/ajax', and ViewAjaxController returns 404, because there are no 'view_name' and 'view_display_id' parameters in form request.

Steps to reproduce

  • compose require drupal/commerce
  • Install Drupal with standard profile
  • Enable commerce_cart module (and dependencies)
  • Add store at /store/add/online
  • Add two products with variants at /product/add/default
  • Edit default Products view at /admin/structure/views/view/commerce_products
  • - set Format section to show Product entities instead of fields
  • - set Pager to 1 per page
  • - enable "Use AJAX" on the view
  • Visit /admin/commerce/products
  • Press the add to cart button
  • Navigate to page 2
  • Press the add to cart button

Proposed resolution

  • Modify ViewAjaxController to handle form requests
  • Or totally modify form API, to use some other route as form action (as it was in Drupal 7)

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

gun_dose created an issue. See original summary.

lukasss’s picture

Also have this problem

gun_dose’s picture

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

Changed version to 8.8.x-dev, because it is still actual.

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). 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.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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.

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

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

pavelculacov’s picture

Some solution???

nod_’s picture

Issue tags: +JavaScript

consolidating issues under the JavaScript tag

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.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.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.

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.

mstrelan’s picture

Issue summary: View changes
Issue tags: -JavaScript +JavaScript, +Bug Smash Initiative

Reviewing this for Bug Smash. Can confirm it's still relevant in 10.1.x. Updating steps to reproduce for those of us less familiar with commerce. Would be good to find a way that doesn't require contrib modules though.

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.

berdir’s picture

Did also run into this one with commerce.

It's related to general set of issues with the fact that views uses a separate route for ajax updates of a view, causes all kinds of problems, for example also #2823541: Table clicksort is lost when using views exposed filter & Pager exposed '#items'. Now that we have GET ajax requests, I'm wondering if we should somehow revert this and do those things as regular ajax requests on the current route. Or find a way to more fully simulate the original request context, for example by adding a custom request object. That would then likely also require #2505339: Stop using getMainRequest() to build $form['#action'].

johnv’s picture

Title: Ajax forms doesn't work properly with ajax views. » Pager in AJAX view results in Ajax forms problem

There is an identical issue in the 'media library' module, when using the 'add media' button.

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.