Coder Social home page Coder Social logo

Support for jQuery 4 about select2 HOT 12 OPEN

marcellov7 avatar marcellov7 commented on June 9, 2024 2
Support for jQuery 4

from select2.

Comments (12)

marcellov7 avatar marcellov7 commented on June 9, 2024 4

https://github.com/marcellov7/select2/tree/support-jQuery-4.0.0-beta
I should have sorted everything out, it seems OK in the testing part too.
Please review and pull request if necessary.

Thanks

from select2.

jonblatho avatar jonblatho commented on June 9, 2024 3

I'm sure I don't speak for everyone, and I'm not sure how much effort the jQuery 4 migration will require, but personally as a user, if substantial effort is going to be spent on a migration I'd much rather it be spent on removing the jQuery dependency altogether (#6196).

from select2.

JCCChris avatar JCCChris commented on June 9, 2024 2

I would love it if this project would refactor to eliminate deprecated calls.

from select2.

jamesleesaunders avatar jamesleesaunders commented on June 9, 2024 1

Would the effort be best simply refactoring the bits of code (if any) which uses these?

Otherwise if you were to be running the jQuery migrate add-on it would it still be complaining that these functions are deprecated? https://github.com/jquery/jquery-migrate

That said, granted it would still work.

from select2.

jamesleesaunders avatar jamesleesaunders commented on June 9, 2024

One first observation testing select2 with jQuery4 is:

  • jQuery.isArray is deprecated; use Array.isArray

jQuery: 3.7.1
select2: 4.1.0-rc.0
django-select2: 8.1.2

        if (self.options.get('debug') && window.console && console.error) {
          // Check to make sure that the response included a `results` key.
          if (!results || !results.results || !$.isArray(results.results)) {             <--- HERE
            console.error(
              'Select2: The AJAX results did not return an array in the ' +
              '`results` key of the response.'
            );
          }
        }
jquery.js:1 JQMIGRATE: Migrate is installed with logging active, version 3.4.1
jquery.js:1 jQuery Version 3.7.1 Loaded
jquery.js:1 JQMIGRATE: jQuery.isArray is deprecated; use Array.isArray
a @ jquery.js:1
t.<computed> @ jquery.js:1
n._resolveLanguage @ select2.full.min.js:2
n.applyFromElement @ select2.full.min.js:2
e @ select2.full.min.js:2
d @ select2.full.min.js:2
(anonymous) @ select2.full.min.js:2
each @ jquery.js:1
each @ jquery.js:1
r.fn.select2 @ select2.full.min.js:2
initHeavy @ django_select2.js:48
(anonymous) @ django_select2.js:56
each @ jquery.js:1
$.fn.djangoSelect2 @ django_select2.js:53
(anonymous) @ django_select2.js:71
l @ jquery.js:1
c @ jquery.js:1
setTimeout (async)
(anonymous) @ jquery.js:1
u @ jquery.js:1
fireWith @ jquery.js:1
fire @ jquery.js:1
u @ jquery.js:1
fireWith @ jquery.js:1
ready @ jquery.js:1
Z @ jquery.js:1
jquery.js:1 console.trace
a @ jquery.js:1
t.<computed> @ jquery.js:1
n._resolveLanguage @ select2.full.min.js:2
n.applyFromElement @ select2.full.min.js:2
e @ select2.full.min.js:2
d @ select2.full.min.js:2
(anonymous) @ select2.full.min.js:2
each @ jquery.js:1
each @ jquery.js:1
r.fn.select2 @ select2.full.min.js:2
initHeavy @ django_select2.js:48
(anonymous) @ django_select2.js:56
each @ jquery.js:1
$.fn.djangoSelect2 @ django_select2.js:53
(anonymous) @ django_select2.js:71
l @ jquery.js:1
c @ jquery.js:1
setTimeout (async)
(anonymous) @ jquery.js:1
u @ jquery.js:1
fireWith @ jquery.js:1
fire @ jquery.js:1
u @ jquery.js:1
fireWith @ jquery.js:1
ready @ jquery.js:1
Z @ jquery.js:1

from select2.

jamesleesaunders avatar jamesleesaunders commented on June 9, 2024

Actually, stand down on the isArray comment above. This looks to be an issue with django-select2 including an older version of select2 (4.0.13). It looks like you have already replaced all instances of $isArray in the latest (4.1.0-rc.0).

I have raised issue over on the django-select2 side: codingjoe/django-select2#267

from select2.

jamesleesaunders avatar jamesleesaunders commented on June 9, 2024

Also see #6253

from select2.

marcellov7 avatar marcellov7 commented on June 9, 2024

In general, it seems to work, but a more in-depth analysis would be needed.

from select2.

marcellov7 avatar marcellov7 commented on June 9, 2024

I'm sure I don't speak for everyone, and I'm not sure how much effort the jQuery 4 migration will require, but personally as a user, if substantial effort is going to be spent on a migration I'd much rather it be spent on removing the jQuery dependency altogether (#6196).

I don't think it's strictly necessary given the nature of the plugin, there are several alternatives out there that work very well without jQuery. Also because the time it would take you to rewrite things without jQuery (if ever a Select2 without jQuery will ever be released) you have already made the switch to another one without jQuery.
Furthermore, with ChatGPT you would quickly switch to an alternative. 🤣

jQuery 4 brings notable improvements and since Select2 is incorporated into this, it is in my opinion important to do a check to determine if any problems with jQuery v4 come out, but it seems to work very well for the moment.

I opened the issue only to encourage those who are more familiar than me to carry out a more in-depth check based on the deprecate elements in jQuery 4.

from select2.

Nedlinin avatar Nedlinin commented on June 9, 2024

@marcellov7 : According to jQuery, camelCase no longer exists: https://blog.jquery.com/2024/02/06/jquery-4-0-0-beta/

It is used here:

var camelKey = $.camelCase(key);

Not sure what else might be broken but this one at least stood out to me as broken on one of my sites.

from select2.

JCCChris avatar JCCChris commented on June 9, 2024

Seems like it would be possible to inject the missing functions back into jQuery and use the native functions and add the extra bit that jQuery added such as null handling.

Anyone see any problems with the following code to add the missing functions back in: (after jQuery but before select2)

jQuery.isArray = Array.isArray || function (value) {
return Object.prototype.toString.call(value) === '[object Array]';
};
jQuery.trim = function (text) {
return text == null ? "" : text.trim();
};
I didn't need to replace camelCase() for some reason, but that might need to be filled in too.

from select2.

sabas avatar sabas commented on June 9, 2024

see #6196

from select2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.