Problem/Motivation

Drupal 11 replaced jQuery with version 4, which removes some deprecated functions (more info). Spectrum library use $.isArray which breaks the whole input (and any following input that also uses spectrum).

Uncaught TypeError: $.isArray is not a function
at applyOptions (spectrum.js?v=1.6.0:252:34)
at initialize (spectrum.js?v=1.6.0:282:13)
at spectrum (spectrum.js?v=1.6.0:960:9)
at HTMLInputElement. (spectrum.js?v=1.6.0:1200:25)
at Function.each (jquery.min.js?v=4.0.0-beta.2:2:2876)
at T.fn.init.each (jquery.min.js?v=4.0.0-beta.2:2:1386)
at $.fn.spectrum (spectrum.js?v=1.6.0:1198:41)
at HTMLDivElement. (color_field_widget_spectrum.jquery.js?v=1.6.0:28:24)
at Function.each (jquery.min.js?v=4.0.0-beta.2:2:2876)
at T.fn.init.each (jquery.min.js?v=4.0.0-beta.2:2:1386)

Steps to reproduce

  1. Create a color field
  2. Set form display widget to "Color spectrum"
  3. Enable "Show palette" in widget settings
  4. Add some colors to the palette
  5. Try the input

Proposed resolution

The Spectrum library has not been updated in the last 5 years, so it is very unlikely that it will receive a new update. So far I have not seen any further compatibility issues with jQuery 4 (I haven't looked in depth either), therefore I suggest polyfilling the $.isArray with Array.isArray function for Spectrum library in color_field_widget_spectrum.jquery.js

// jQuery 4 polyfill for isArray function
$.isArray = $.isArray || Array.isArray;

Remaining tasks

Check for further jQuery 4 related issues.

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

lordgretix created an issue. See original summary.

shivam_tiwari’s picture

Status: Active » Needs work

I created MR according to suggestions, but it gets failed. So need to work here.

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

nickdickinsonwilde’s picture

Status: Needs work » Fixed

Fantastic, thanks.
Merged (test failure was not related to this change but in the main repo)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.