Ajax error ajax.$form.ajaxSubmit() is not a function

Created on 26 June 2016, over 8 years ago
Updated 6 September 2024, 2 months ago

Problem/Motivation

Different Drupal forms throw an ajax.$form.ajaxSubmit error on submit.

This has affected users at image upload, Block editing within Layout Builder sections, and ajax submissions for webforms. It is blocking development of various site items.

Steps to reproduce

Adding any elements to a form also gives the same error.

Steps:

  1. Install & enable the webform module .
  2. Add a new test form.
  3. Click the "+ Add element" button.
  4. Pick any element type, and fill in the form to create a new element.
  5. Click the "Save" button.

Proposed resolution

Fix the bug with ajax so that Drupal users can add / modify webforms, successfully upload images etc.

Remaining tasks

Test the proposed patch.
Merge it if good.

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

NA

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Ajax 

Last updated 2 days ago

Created by

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

  • 🇺🇸United States jcandan

    On a new D9.5.x site with a Radix 5.0.8 backed sub-theme, and Bootstrap Layout Builder module.

    For me, the error alert comes up after I attempt to edit a block in a layout; so, previous attempts to add blocks work. Have not attempted to reproduce this in a vanilla Drupal instance.

    Patch #12 addresses the error from Layout Builder off canvas Block editing.

    This fix looks appropriate as it applies the fix to the common drupal.ajax library dependency.

  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States timodwhit

    core/jquery.form has been deprecated. For long term maintainability, this patch would likely need to be updated.

  • 🇺🇸United States jcandan

    Good catch. To recap what they did, to maintain compatibility, core added an internal.jquery.form library, a duplicate of jquery.form, and updated its usage throughout core.

    Additionally, 00991b9 says not to add new usage to core:

    # Internal library. Do not depend on it outside core nor add new core usage.

    Active support for 9.5.x ended June 21, 2023, so this is not likely to be adopted since it is not a security issue.

    Unless someone agrees this should be changed and re-rolls a patch using internal.jquery.form, this can be closed (won't fix). Any Drupal 9 developers wishing to use the patch #12 supplied may do so until they upgrade to Drupal 10.

    However, I am curious to know if this issue exists in Drupal 10. Note: Drupal 10 still uses this library.

    If it does, then this simple fix with internal.jquery.form would be appropriate, except for the directive not to add new core usage.

    Otherwise, a non-jquery fix would be necessary.

    Can someone confirm whether this issue occurs in Drupal 10?

  • Issue was unassigned.
  • 🇺🇦Ukraine taraskorpach Lutsk

    I encountered the same error while updating to d10.1.1. I have a custom form that includes a select field with an "#ajax" key and a "change" event. When I attempt to change the select value on the page that contains the form, I receive an error as mentioned in the issue description: ajax.$form.ajaxSubmit is not a function. As a result, I had to write a patch for internal.jquery.form.

    I attempted to load the library through a custom module and even tried altering the weight to load the library earlier, but neither approach was successful. Would anyone be willing to try and provide a comprehensive fix?

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    CI aborted
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Patch Failed to Apply
  • 🇺🇦Ukraine taraskorpach Lutsk

    Re-roll

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    29,459 pass
  • 🇺🇸United States kkaya

    This error also occurs in Drupal 10.1.2 when trying to delete a menu link:

    An error occurred while attempting to process /admin/structure/menu/item/#/delete?destination=/admin/structure/menu/manage/main&_wrapper_format=drupal_ajax: ajax.$form.ajaxSubmit is not a function. (In 'ajax.$form.ajaxSubmit(ajax.options)', 'ajax.$form.ajaxSubmit' is undefined)

  • 🇮🇳India bhanu951

    This issue still occurs in latest 10.2.x version. But the patch from #19 doesn't fix it.

    To reproduce this issue, Install Stripe Module and enable its submodule stripe_examples and navigate to https://d10.local/stripe_examples/form/simple_checkout after adding stripe test API keys at https://d10.local/admin/config/stripe and try to submit the form. You will be getting this error.

  • Status changed to Needs review 10 months ago
  • Status changed to Needs work 10 months ago
  • 🇺🇸United States smustgrave

    Issue summary should follow standard template. Have added it but TBD sections will have to be filled out.

  • Also having this issue in version 10.1.8 when trying to add a handler to a webform. I applied the patch from #19 but am still getting the ajax error. Do I need to do something to make the patched file load?

  • Are steps to reproduce still needed? In Webform (on Drupal 10.1.8), these steps do it for me:

    1. Install webform module and add a test form
    2. Go to admin/structure/webform/manage//handlers
    3. Click "+ Add handler" button.
    4. Choose any handler, e.g. Action or Remote post, and click the "Add handler" button @ right
    5. Put any values in, and click "Save" at the bottom of the dialog.
    6. See the Ajax error.
  • Re #28 Adding any elements to a form also gives the same error.

    Steps:

    1. Install webform module and add a new form.
    2. Click the "+ Add element" button.
    3. Pick an element type, and fill in the form to create a new element.
    4. Click the "Save" button.

    I will add this to the issue itself.

  • The patch in #24 works for me, after clearing all the caches.

  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    In \Drupal\Core\Render\Element\RenderElement::preRenderAjaxForm() we do:

          $element['#attached']['library'][] = 'core/internal.jquery.form';
          $element['#attached']['library'][] = 'core/drupal.ajax';
    

    So one question I have is how are we rendering a form and added stuff that causes an ajax submit without hitting this code?

    Also if we are going to add the dependency to core/drupal.ajax then we should remove it from the views library dependencies (after checking that it is not directly used) and RenderElement::preRenderAjaxForm()

  • 🇪🇸Spain jorgero Sevilla

    I have a Drupal 9.5.11 installation, and I've developed a custom module with a form that utilizes the '#ajax' property. While it works in Chrome, it doesn't function properly in Firefox and Edge. I resolved the issue by adding 'core/drupal.ajax' to the dependencies in my (custom theme) theme.libraries.yml file.

  • 🇺🇸United States papagrande US West Coast

    I'm getting sporadic reports from a customer of this error on a hosted site with a webform using a file upload field, but can't reproduce the error myself, either locally or in production. Can others provide information about:

    • Do the errors happen in all browsers?
    • Are you logged in or not? Do the errors happen for anonymous users?
    • What AJAX settings are enabled in the webform?
    • Is the site local or hosted? If hosted, which provider?
    • Is JavaScript aggregation enabled?
    • Is a CDN in front of the site? If so, which one and are there special caching rules in place?
  • 🇬🇧United Kingdom mustanggb Coventry, United Kingdom
  • hi in drupal 10.3.1 this patch solve my problem.
    #36

    thank you.

  • 🇨🇦Canada joseph.olstad

    #36 is identical to the MR 6052 https://git.drupalcode.org/project/drupal/-/merge_requests/6052.patch

    MR 6052 is identical to patch #18 which is what all these latest ones are based on.

    to pin on the MR commit you could specify the hashtag as follows:

    https://git.drupalcode.org/project/drupal/-/commit/c2b4fd62.patch

    Or use the diff instead.
    https://git.drupalcode.org/project/drupal/-/commit/c2b4fd62.diff

  • Still encountering this problem after upgrade to 10.3.3.

    What are the steps after updating core/core.libraries.xml?

    Attempting to use simple-oath to generate keys - uses an ajax call.

    Thanks.
    ==============
    ajaxTrustedUrl: {}
    dependencies:
    - core/jquery
    - core/internal.jquery.form
    - core/drupal
    - core/drupalSettings
    - core/drupal.progress
    - core/once
    - core/tabbable
    - core/loadjs
    - core/drupal.message

  • #36 fixed the issue for me in Drupal 10.3.6

Production build 0.71.5 2024