jquery once is deprecated

Created on 16 December 2023, 7 months ago
Updated 18 December 2023, 6 months ago

Problem/Motivation

Error reported on the javascript console in drupal-10.

drupal.js?v=10.1.7:64 Uncaught TypeError: $(...).once is not a function
at Object.attach (animated_scroll_to_top.js?s5bxmp:4:26)

Jquery once was removed

https://www.drupal.org/node/3158256 โ†’

Steps to reproduce

Proposed resolution

The steps are listed in the task

After (removing jQuery dependency)
# mymodule.libraries.yml
myfeature:
js:
js/myfeature.js: {}
dependencies:
- core/drupal
- core/once
# js/myfeature.js
(function (Drupal, once) {
Drupal.behaviors.myfeature = {
attach(context) {
const elements = once('myfeature', '[data-myfeature]', context);
// `elements` is always an Array.
elements.forEach(processingCallback);
}
};

// The parameters are reversed in the callback between jQuery `.each` method
// and the native `.forEach` array method.
function processingCallback(value, index) {}
}(Drupal, once));

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

๐Ÿ‡ฆ๐Ÿ‡บAustralia interlated

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024