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.

JQuery Conflict with Django.ModelAdmin.autocomplete_fields

See original GitHub issue

The problem is caused by the use of different jQuery files. Django relies on jquery.js (the one with ajax functions) to work, while map-widgets uses the jquery-3.3.1.slim.min.js (which has ajax stripped away). autocomplete_fields will thus stop working.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

4reactions
SiddharthPantcommented, Sep 7, 2019

For now my temporary fix is to simply override the class and remove the slim from jquery and then everything works fine in the admin panel by using my custom widget.

from django import forms

from mapwidgets.settings import mw_settings
from mapwidgets.widgets import GooglePointFieldWidget, minify_if_not_debug


class CustomGooglePointWidget(GooglePointFieldWidget):
    @property
    def media(self):
        css = {"all": [minify_if_not_debug("mapwidgets/css/map_widgets{}.css")]}

        js = [
            "https://code.jquery.com/jquery-3.3.1.min.js",
            "https://maps.googleapis.com/maps/api/js?libraries=places&language={}&key={}".format(
                mw_settings.LANGUAGE, mw_settings.GOOGLE_MAP_API_KEY
            ),
        ]

        if not mw_settings.MINIFED:
            js = js + [
                "mapwidgets/js/jquery_class.js",
                "mapwidgets/js/django_mw_base.js",
                "mapwidgets/js/mw_google_point_field.js",
            ]
        else:
            js = js + ["mapwidgets/js/mw_google_point_field.min.js"]

        return forms.Media(js=js, css=css)

3reactions
yakkycommented, Mar 31, 2020

@erdem great! thanks for fixing this 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prevent Error: 403 in ModelAdmin.autocomplete_fields?
That's because of the conflict between DAL and Django 3.2 + versions. If you turn DAL off it can solve this problem.
Read more >
The Django admin site
One of the most powerful parts of Django is the automatic admin interface. ... To avoid conflicts with user-supplied scripts or libraries, Django's...
Read more >
Change log for django-autocomplete-light - Read the Docs
#463 Update jquery-autocomplete-light which contains IE8 fixes. ... Note that we have also extracted django admin specific hooks from widget.js into ...
Read more >
Using jQuery.noConflict() instead of jQuery ... - Google Groups
admin places jQuery in its own namespace `django.jQuery`. In this way other jQuery instances should not conflict with it. 2) It also removes...
Read more >
[Solved]-Jquery Autocomplete limit results with Django-django
Difficulty with Django and jQuery (why is $ undefined in the admin app?) Limit the queryset of autocomplete fields in Django · Incorrect...
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