question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cannot use select2 on grappelli admin dashboard

See original GitHub issue

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?!

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:4
  • Comments:37 (15 by maintainers)

github_iconTop GitHub Comments

3reactions
ychabcommented, Nov 16, 2016

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 collectstatic command itself show us the fix :

Found another file with the destination path ‘admin/js/jquery.init.js’. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a uniq ue path.

However, I didn’t understand that if the file was previously collected, it won’t be override. So even if INSTALLED_APPS is correctly sorted, the command won’t override the previous admin/js/jquery.init.js from django.contrib.admin (or grapelli).

By removing the file copied in static dir (or dropping the static dir itself), the next collectstatic will properly copied the first one admin/js/jquery.init.js founded, which is the one from dal due to ordering of the setting INSTALLED_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:

  1. add dal and dal_select2 in the top of the INSTALLED_APPS
  2. drop your collected static dir (or at least admin/js/jquery.init.js)
  3. collect static file python manage.py collectstatic

Just in case, check that your served jquery.init.js is the one from dal.

Hope it could help.

3reactions
carmichaelalonsocommented, Aug 30, 2016

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…

class Media:
        js = (
            'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js',
        )

… 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 collectstatic with 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

django-select2-admin-filters - Python package - Snyk
A simple extension to Django app to render filters in django admin panel as autocomplete widget. For more information about how to use...
Read more >
Django Grappelli not selecting all on clicking select all checkbox
I am having some issues on my admin panel ...
Read more >
django-select2-admin-filters - PyPI
A simple extension to Django app to render filters in django admin panel ... This extension is based on django-select2 and works with...
Read more >
django-autocomplete-light Documentation
So, we're going to override the default ModelForm fields, to use a widget to select a Model with Select2, in our case by...
Read more >
yourlabs - Bountysource
cannot use select2 on grappelli admin dashboard $ 0 ... Created 6 years ago in yourlabs/django-autocomplete-light with 37 comments. Hi,. I used from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found