modlinltd / django-advanced-filters

Add advanced filtering abilities to Django admin
https://pypi.org/project/django-advanced-filters/
MIT License
771 stars 173 forks source link

Select2 fails to load #39

Closed jamiecollinson closed 7 years ago

jamiecollinson commented 7 years ago

I've just upgraded an old django project from 1.3 -> 1.8 and am trying to add django-advanced-features to replace an old custom filtering application.

I've installed django_advanced_filters 1.0.5, and django_easy_select2 1.2.5. I've followed the installation guide and successfully added the AdminAdvancedFiltersMixin to one of my models. I can see the admin templates are loading correctly but I seem to be getting JS errors related to select2.

E.g. on http://localhost:8080/admin/advanced_filters/advancedfilter/2/ I see:

Uncaught TypeError: Cannot read property 'fn' of undefined
    at select2.min.js:21
    at select2.min.js:21

And on my model changelist page (http://localhost:8080/admin/mymodel/):

select2.min.js:21 Uncaught TypeError: Cannot read property 'fn' of undefined
    at select2.min.js:21
    at select2.min.js:21

advanced-filters.js:140 Uncaught TypeError: $(...).select2 is not a function
    at HTMLInputElement.<anonymous> (advanced-filters.js:140)
    at Function.each (jquery.min.js:2)
    at m.fn.init.each (jquery.min.js:2)
    at OperatorHandlers.self.destroy (advanced-filters.js:139)
    at HTMLDocument.<anonymous> (advanced-filters.js:150)
    at j (jquery.min.js:2)
    at Object.fireWith [as resolveWith] (jquery.min.js:2)
    at Function.ready (jquery.min.js:2)
    at HTMLDocument.J (jquery.min.js:2)

This looks to me like some kind of jquery load order issue, and I'm aware django does some funny things with various versions, but I'm a bit stuck on how to debug. Can anyone point me in the right direction? I did wonder if it's due to the several difference versions of jquery loading and re-initialising $, but I believe django does some clever stuff to namespace the versions. In case it's helpful here are the .js files loading on my model changelist page:

jsi18n/ 200 script  (index) 2.7 KB  246 ms
core.js 200 script  (index) 7.8 KB  89 ms
jquery.js   200 script  (index) 278 KB  126 ms
jquery.init.js  200 script  (index) 557 B   88 ms
RelatedObjectLookups.js 200 script  (index) 4.8 KB  113 ms
actions.js  200 script  (index) 5.0 KB  118 ms
urlify.js   200 script  (index) 6.3 KB  116 ms
prepopulate.js  200 script  (index) 1.6 KB  115 ms
select2.min.js  200 script  (index) 59.0 KB 12 ms
jquery.min.js   200 script  (index) 93.9 KB 14 ms
orig_inlines.js 200 script  (index) 11.3 KB 14 ms
jquery.magnific-popup.js    200 script  (index) 20.7 KB 20 ms
advanced-filters.js 200 script  (index) 5.0 KB  22 ms
jquery_pre.js   200 script  (index) 298 B   7 ms
jquery.min.js   200 script  (index) 29.5 KB 44 ms
jquery_post.js  200 script  (index) 313 B   10 ms
toolbar.js  200 script  (index) 12.4 KB 8 ms
toolbar.sql.js  200 script  (index) 584 B   10 ms
toolbar.template.js 200 script  (index) 589 B   11 ms
jamiecollinson commented 7 years ago

Friendly bump in case anyone can help - I've really hit a brick wall with this and would love to use the project if I can but will shortly have to abandon it if I can't resolve :-(

asfaltboy commented 7 years ago

Hi @jamiecollinson , thank you for reporting the issue, it seems that in the last version we introduced an issue with the loading order of select2.js. The referenced PR should fix it - I would appreciate if you could give that branch a try.