Closed
Description
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
- Create the following model:
from django.db import models
class Person(models.Model):
title = models.CharField(max_length=10, choices=[('Dr.', 'Dr.'), ('Rep.', 'Rep.')])
- 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
-
Visit the admin page for the model (admin/app/person/add/)
-
Open the browser console and find the exception thrown in en.js
Expected Behavior
No exception is thrown and the i18n works as expected