Problem/Motivation
I want a form to be ajax submitted. As per the docs, I added class use-ajax-submit to the submit button of the form. The ajax submit is working if the page has the admin toolbar, but for users who cannot see the admin toolbar, for them it throws error:
drupal_ajax: ajax.$form.ajaxSubmit is not a function
I had to add core/jquery.form and core/drupal.ajax libraries to the form, to make it work.
Proposed resolution
Libraries core/jquery.form and core/drupal.ajax should be added by itself if use-ajax-submit class is added to the submit button.
Remaining tasks
N/A
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Comments
Comment #2
subhojit777Comment #3
subhojit777Comment #4
subhojit777Comment #5
subhojit777Comment #6
nod_we don't parse information in classes to add libraries. The docs needs to be updated to say those dependencies are needed when using this class.
Comment #8
subhojit777Comment #18
smustgrave commentedKnow we are trying to move away from jQuery right? So is this still needed?
Comment #19
nod_we're trying but it's not something in the near future. To make docs accurate that would be needed.
The comment could use some work, in particular saying those 2 things are libraries to attach.
Comment #20
kunalgautam commentedPatch for Drupal 10.1
Comment #21
smustgrave commentedThank you @kkalashnikov but the patch #8 still applied cleanly to 10.1 so the reroll was not needed. Removing credit for that.
You can verify if a patch still applies to a specific branch by clicking test/retest under it.
Also with patches, even rerolls, please upload an interdiff
Thank you @nod_ for explaining that. So the documentation change in #8 looks good and simple then
Thanks
Comment #22
kunalgautam commentedHello @smustgrave this is the interdiff of #8 and #20 patch.
Comment #23
catch#19 still needs to be addressed - the comment should explicitly say these are libraries, and use attach/attached/#attached instead of 'include'.
Comment #24
mrinalini9 commentedUpdated patch #8 by addressing #23, please review it.
Comment #25
smustgrave commentedNot sure if that can be cleaned up more but adds value as is currently.
Comment #26
catchIt still doesn't say explicitly that these are libraries. like 'you will need to attach the libraries .... to the form' or something.
Comment #28
timodwhit commentedThe pull request/solution no longer seems valid: https://www.drupal.org/node/3293156
The user would need to create a new library for jquery.form and then attach it to the form it appears.
Comment #29
timodwhit commentedComment #30
bhanu951 commentedI think we can close it as a duplicate of #2755791: Ajax error ajax.$form.ajaxSubmit() is not a function as it has working patch.