Problem/Motivation

Steps to reproduce

Proposed resolution

  • In misc/ajax.js, replace the call to $.ajaxSubmit() with fetch() if possible, or $.ajax() if that's an easier step and we can then replace $.ajax() with fetch() in a followup.
  • For BC, we should preserve at least some of the existing events, like beforeSerialize(), beforeSubmit(), and beforeSend(). If in addition to those 3 it makes sense to preserve all of the existing $.ajax() events, that might be a point in favor of using $.ajax() over fetch() for now, especially if that can work easily enough with FormData.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3189416

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

bnjmnm created an issue. See original summary.

nod_’s picture

I think we should start from scratch on the JS side, figure out a simpler api (and a much clearer lifecycle especially) for this and provide a compatibility layer that can be used to understand jquery-style ajax calls. It will be an opportunity to clean up the progress thing, the effects. I don't think the php side will need much changes.

The hard part is probably going to be the ajax commands, and jquery form replacement like you said.

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.

andypost’s picture

Issue tags: +JavaScript
avpaderno’s picture

Title: [meta] how to approach core/drupal.ajax divorcing jQuery? » [meta] How do we approach core/drupal.ajax divorcing from jQuery?
larowlan’s picture

nod_’s picture

This is what jquery-form already uses :) Half of that library is to support file uploads for older browsers through an iframe. Nowadays most of what's in the library is already covered by FormData.

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.

effulgentsia’s picture

In #3145958: [META] Re-evaluate use of Backbone.js in core, we decided to keep a forked copy of Backbone as an internal dependency for Tour, Toolbar, and Contextual Links at least until such time as those modules can be refactored away from Backbone.

I wonder if we should do the same thing here: make a forked copy of jquery-form for internal use by drupal.ajax, but deprecate/remove it as a public library for contrib's use. Then, we can refactor drupal.ajax during Drupal 10's lifetime rather than having to complete that refactor prior to Drupal 10's beta. Of course, if someone is able to complete that refactor before D10's beta, great! But this would buy us time if we can't get that done in time.

nod_’s picture

we could deprecate the library and create a new internal one like we did for backbone

nod_’s picture

bnjmnm’s picture

Status: Active » Needs review
StatusFileSize
new1.74 KB
new2.23 KB
bnjmnm’s picture

Disregard #12 I'll make a dedicated issue for it as it is specific to jQuery.form

The jquery form internalizing is moved to #3280359: Make jQuery.form internal

The last submitted patch, 12: 3189416-12-10x.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 12: 3189416-12-94x.patch, failed testing. View results

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.

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.

catch’s picture

Issue tags: -JavaScript +JavaScript

Do we need a new dedicated issue for removing jQuery.form usage from views_ui and views AJAX? That still seems like the next step here afaict.

effulgentsia’s picture

It wouldn't be a straightforward 1:1 port, but something that might be worth considering is replacing Drupal's whole AJAX system with https://htmx.org/. I think htmx would give us most/all of the features we're used to with Drupal's AJAX, but figuring out the right amount of backwards compatibility wrappers to add would be the tricky part.

stovak’s picture

++HTMX

xjm’s picture

Priority: Normal » Critical

JQuery Form does not seem to be maintained anymore, so bumping priority.

catch’s picture

I think we probably still need a dedicated issue for getting rid of jquery.form in views_ui/views_ajax per #19.

effulgentsia’s picture

Title: [meta] How do we approach core/drupal.ajax divorcing from jQuery? » Remove jQuery Form dependency from misc/ajax.js
Category: Plan » Task
Issue summary: View changes

Re #23, I don't think Views / Views UI actually use jQuery Form directly, they only use it via Drupal.ajax. I think the only reason they declare a dependency on the plugin is because they instantiate Drupal.ajax() objects from JS code rather than always going through PHP's #ajax, so they don't get the dependency brought in automatically.

In other words, to remove it from Views / Views UI, we need to remove it from misc/ajax.js first. Changing this issue's title and summary to focus on that.

effulgentsia’s picture

Issue summary: View changes
effulgentsia’s picture

Status: Needs work » Needs review
StatusFileSize
new5.04 KB

I haven't tested this at all, so this might fail hard, but something along these lines is what I recommend.

smustgrave’s picture

Status: Needs review » Needs work

Seems to have CC failure, could we switch to an MR? Hiding older patches for clarity.

Nitin shrivastava made their first commit to this issue’s fork.

finnsky’s picture

Also seems
$.fieldValue(this.element);
is used from jquery form plugin

effulgentsia’s picture

Re #20, since converting to HTMX is too large scope for this issue, I opened #3404409: [Plan] Gradually replace Drupal's AJAX system with HTMX as a separate Ideas issue.

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

catch’s picture

catch changed the visibility of the branch 11.x to hidden.

catch’s picture

Hid one branch, rebased the other one, fixed one js linting issue so that tests will run.

catch’s picture

Manually tested.

First I uninstall big_pipe because that depends on the AJAX system and was throwing its own errors, just to reduce variables, we probably need to update some things there though.

Without big_pipe, if I change the allowed values on a field form (i.e. /admin/structure/types/manage/article/fields/node.article.body), I get:

An error occurred while attempting to process /admin/structure/types/manage/article/fields/node.article.body?_wrapper_format=drupal_ajax: Illegal invocation

So that seems like somewhere to start.

This unfortunately does not show up in the javascript test error log, we just get unexpected dialog or similar.

finnsky’s picture

Issue summary: View changes
catch’s picture

Made a commit which at least gets past the illegal invocation error - needs someone who knows what they're doing to fix it properly.

Next up is $.fieldValue is not a function.

gábor hojtsy’s picture

Issue summary: View changes
Issue tags: +Drupal 11

Added the situation with jQuery 4 into the issue summary's top.

catch’s picture

I messed up the commit history here when I slightly changed the approach. We now have two branches:

1. https://git.drupalcode.org/project/drupal/-/merge_requests/6530#note_263731 - this is the original approach forking/reimplementing everything we need* from jquery form.

2. https://git.drupalcode.org/project/drupal/-/merge_requests/6486#note_263745 a hybrid approach which leaves the jquery methods in their own fork.

*I think I have discovered the cause of most of the test failures remaining in #1, and it's not good news. The original draft here didn't reimplement the ajaxSubmit function. Because of the way ajax.js checks for this, if it's missing, it just skips it, and then AJAX form submits fail with neither console nor PHP errors.

The ajaxSubmit method is massive, so if we copy that to ajax.js, even if we can refactor it a bit, then what we've really done is forked jquery form again into our code base.

I therefore am thinking, at least to get us onto jQuery 4, we should just fork jQuery form and fix the four jQuery 4 issues in it, which is what #3419734: [jQuery 4] jquery-form is unmaintained and not jQuery 4 compatible, fork it into core does. That absolutely does not preclude continuing here, but we might end up making the decision to jump straight to HTMX too.

effulgentsia’s picture

The ajaxSubmit method is massive

But with modern browsers we shouldn't need 95% of it. The submitForm() function in #26 conceptually should be a drop-in replacement for ajaxSubmit(). It didn't seem to work and I haven't had time to look into it further yet but my hunch is that we shouldn't need to add all that much more code into it to make it work.

I therefore am thinking, at least to get us onto jQuery 4, we should just fork jQuery form and fix the four jQuery 4 issues in it

Yes, I agree with doing that so as not to block our jQuery 4 upgrade on this issue.

larowlan’s picture

Hiding patches

xjm’s picture

Priority: Critical » Major

Per @longwave, #3419734: [jQuery 4] jquery-form is unmaintained and not jQuery 4 compatible, fork it into core has removed this from the critical path, so downgrading to major.

xjm credited longwave.

xjm’s picture

longwave’s picture

Priority: Major » Critical

Yeah this is no longer strictly necessary for 11.0.0 as per #43 we can ideally refactor it away given there is apparently a lot of cruft that supports old browsers nowadays.

longwave’s picture

Priority: Critical » Major
xjm’s picture

Issue tags: -Drupal 11 +Drupal 12

@longwave, @catch and I discussed the priority of this issue a bit, and while it's not in the critical path for D11, it could be considered critical to complete for D12, and this and other open issues should be reparented to the D12 meta when we file it shortly.

catch’s picture

I think we should strongly consider doing #3404409: [Plan] Gradually replace Drupal's AJAX system with HTMX instead of this issue. It's clear from both this issue and #3419734: [jQuery 4] jquery-form is unmaintained and not jQuery 4 compatible, fork it into core that core's JavaScript AJAX API is unmaintained (people do occasionally work on the PHP end of things). So replacing it with a small, well maintained library could simplify things.

catch’s picture

Title: Remove jQuery Form dependency from misc/ajax.js » [PP-1] Remove jQuery Form dependency from misc/ajax.js
Status: Needs work » Postponed

Postponing this until there's a decision on that issue.

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.

quietone’s picture

Status: Postponed » Postponed (maintainer needs more info)
Issue tags: -JavaScript, -Drupal 12

Is there anything to do here now that HTMX is in core?

catch’s picture

Title: [PP-1] Remove jQuery Form dependency from misc/ajax.js » [PP-x] Remove jQuery Form dependency from misc/ajax.js
Status: Postponed (maintainer needs more info) » Postponed

I don't think it's worth actively working on this, we should do #3404409: [Plan] Gradually replace Drupal's AJAX system with HTMX instead so we can remove the AJAX JavaScript entirely. However we're quite far from actually being able to remove this, so postponed seems like the right status tbh. We could also mark it outdated if we want it out of the queue.