Ajax forms doesn't work properly with ajax views.

Created on 24 August 2018, over 6 years ago
Updated 11 September 2024, 3 months ago

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

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
AjaxΒ  β†’

Last updated 2 days ago

Created by

πŸ‡§πŸ‡ΎBelarus gun_dose

Live updates comments and jobs are added and updated live.
  • views

    Involves, uses, or integrates with views. In Drupal 8 core, use the β€œVDC” tag instead.

  • JavaScript

    Affects the content, performance, or handling of Javascript.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    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.

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    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 πŸ› Table clicksort is lost when using views exposed filter Needs work . 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 πŸ“Œ Stop using getMainRequest() to build $form['#action'] Needs work .

Production build 0.71.5 2024