Uncaught TypeError: n.trim is not a function

Created on 19 January 2025, 5 days ago

Problem/Motivation

When used with a recent drupal11 site, the module is not working.
Indeed, jQuery is used in version 4.x.
Unfortunately, the JS code from mondialrelay seems not completely compatible with jquery 4.x,
in the sense there is at least the function "trim" which is used from the js code but absent in jquery 4.x

On my local site, i have altered the drupal/jquery library to add a small shim JS code like this :

if (typeof jQuery.trim === 'undefined') {
  jQuery.trim = function(text) {
    return text == null ? '' : String.prototype.trim.call(text);
  };
}

i have defined this js code and added it to a library called "jquery_trim_shim" in my custom module "custom_module".
then i have implemented this hook in my custom module.

function custom_module_library_info_alter(&$libraries, $module) {
    if ($module == 'core' && isset($libraries['jquery'])) {
       //$libraries['jquery']['dependencies'][] = ' custom_module/jquery_trim_shim';
    }
}

what do you think, should the "commerce_shipping_mondial_relay" adds this JS shim or does something else to still works under d11?

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇫🇷France just_like_good_vibes PARIS

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024