Skip to content

i18n is broken due to missing jQuery import in media 🐛  #292

Closed
@mardukbp

Description

@mardukbp

Bug Description

When using django-select2 in the Django Admin (regardless of the value of settings.LANGUAGE_CODE) the corresponding i18n file (e.g. en.js) throws the following exception in the brower console:

TypeError: Cannot read properties of undefined (reading 'define')
    at en.js:3:106
    at en.js:3:755

The problem is that jquery.init.js is loaded before this file. In order to load it afterwards this line has to be replaced with:

            js=select2_js + i18n_file + ["admin/js/jquery.init.js"] + ["django_select2/django_select2.js"],

Steps to Reproduce

  1. Create the following model:
from django.db import models

class Person(models.Model):
    title = models.CharField(max_length=10, choices=[('Dr.', 'Dr.'), ('Rep.', 'Rep.')])
  1. Create the following admin for the model:
from django.contrib import admin
from django import forms

from django_select2.forms import Select2Widget

from .models import Person


class PersonForm(forms.ModelForm):
    class Meta:
        widgets = {
            'title': Select2Widget
        }


@admin.register(Person)
class PersonAdmin(admin.ModelAdmin):
    form = PersonForm
  1. Visit the admin page for the model (admin/app/person/add/)

  2. Open the browser console and find the exception thrown in en.js

Expected Behavior

No exception is thrown and the i18n works as expected

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions