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
- Create a color field
- Set form display widget to "Color spectrum"
- Enable "Show palette" in widget settings
- Add some colors to the palette
- 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.
Issue fork color_field-3504282
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
Comment #3
shivam_tiwari commentedI created MR according to suggestions, but it gets failed. So need to work here.
Comment #6
nickdickinsonwildeFantastic, thanks.
Merged (test failure was not related to this change but in the main repo)