Attach core_drupal.dialog.ajax only to product page

Created on 26 November 2020, about 4 years ago
Updated 2 October 2024, 3 months ago

On product page (Drupal 9) with variations, if I choose some variation of product (e.g size "M" instead default "S" (e.g)), I see js-errormessage: "ajax_form=1&_wrapper_format=drupal_ajax: s.$form.ajaxSubmit is not a function". After researching I found, that there are missing some js, wich are not automatically loaded:
- core/drupal.dialog.ajax
- core/jquery.form.

So. this scripts I can attach globally, and they will be loaded on all pages, what isn't neccessary, and I think if Drupal doen't load it automaticaly default on all pages, so there is a reason.

So I try to attach this scripts only to product pages, for this:
in product template "commerce-product.html.twig" I attach my custom library, e.g: "{{ attach_library('THEME/products-js') }}" , wich
I create in THEME.libraries.yml:
products-js:
version: 1.0
# js:
# js/products.js: {}
dependencies:
- core/drupal.dialog.ajax
- core/jquery.form

and here is a problem:
this scripts

- core/drupal.dialog.ajax
- core/jquery.form

will be attached to all pages, as if I attach it globally:
in source of front-page I see:
_script src="/core/assets/vendor/jquery.ui/ui/widgets/dialog-min.js?v=1.12.1"__/script_ _script src="/core/misc/dialog/dialog.js?v=9.0.8"_ _/script_ _script src="/core/misc/dialog/dialog.position.js?v=9.0.8"_ _/script_ _script src="/core/misc/dialog/dialog.jquery-ui.js?v=9.0.8"_ _/script_ _script src="/core/misc/dialog/dialog.ajax.js?v=9.0.8"_ _/script_

and the same on product-page

Nothing changed, if I comment out this lines
# js:
# js/products.js: {}

So, can you tell me please, what do I wrong or is there some bug? Thanks

💬 Support request
Status

Active

Version

2.21

Component

Product

Created by

Live updates comments and jobs are added and updated live.
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.

Production build 0.71.5 2024