django-autocomplete-light: cannot use select2 on grappelli admin dashboard
Hi,
I used from autocomplete light in grappelli dashboard but i got this error when load page,
Uncaught TypeError: $(...).select2 is not a function select2.js:8!!!
how can i fix this?!
About this issue
- Original URL
- State: open
- Created 8 years ago
- Reactions: 4
- Comments: 37 (15 by maintainers)
Hi everyone,
Just for other which have this same JS error (without grapelli for me) : to fix the issue, drop the static dir before collecting it.
I think the same error should happen with grappelli and the
collectstaticcommand itself show us the fix :However, I didn’t understand that if the file was previously collected, it won’t be override. So even if
INSTALLED_APPSis correctly sorted, the command won’t override the previousadmin/js/jquery.init.jsfrom django.contrib.admin (or grapelli).By removing the file copied in static dir (or dropping the static dir itself), the next
collectstaticwill properly copied the first oneadmin/js/jquery.init.jsfounded, which is the one from dal due to ordering of the settingINSTALLED_APPS.At least for me, it fix this issue.
I’m not sure we could easily fix it, but we could add some note in install doc? For example:
INSTALLED_APPSadmin/js/jquery.init.js)python manage.py collectstaticJust in case, check that your served
jquery.init.jsis the one from dal.Hope it could help.
I’m using the default Django admin and I’m getting the same issue. I’m following the documentation to show a
ModelSelect2Multiple- I can get the form to show, but I get the error that the OP mentions.I also get
select2.full.js:473 Select2: An instance of jQuery or a jQuery-compatible library was not found. Make sure that you are including jQuery before Select2 on your web page.- I can solve this with the code below in the admin class…… but I don’t think this is the solution. The installed apps layering does not do the trick either and I continue receiving the same error as the OP.
I’ve ran
collectstaticwith no luck. I’m guessing I need to load the jQuery file before the select2 based on other answers I’ve seen on StackOverflow.Has anybody seen something like this before? Django 1.9.2/DAL 3.1.8
I was having this exact issue on 3.5.1, upgraded to 3.7.0dev and it appears to be working.
I’m sorry, I had already released some 3.6.0dev versions back in March 2020 and they have nothing to do with this release, so we’re skipping to 3.7.0
This should be fixed, amongst with many other js order/loading issues by #1162 which I rebased and merged in master 8 days ago
Is it better with 3.7.0 ?
Guys, is this still an issue? Seems like each time I end up here…
That a palliative solution, we need a preventive one.
Le 23 févr. 2017 9:40 PM, “Enrique Paz” notifications@github.com a écrit :