Skip to content

Commit 6b63c54

Browse files
Fix jQuery preference order to prevent conflicts with third-party widgets
When other Django admin widgets (like PrettyJSONWidget, JSONEditor, etc.) load their own jQuery, they overwrite the global `jQuery` variable. Since django_select2.js prefers `jQuery` over `window.django.jQuery`, it ends up using the newly loaded jQuery instance which doesn't have Select2 attached. This causes "$element.select2 is not a function" errors on admin pages. By preferring `window.django.jQuery` (Django's protected instance), we ensure Select2 functionality works regardless of what other widgets do to the global jQuery variable.
1 parent f5c68cd commit 6b63c54

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

django_select2/static/django_select2/django_select2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
} else if (typeof module === 'object' && module.exports) {
66
module.exports = factory(require('jquery'))
77
} else {
8-
// Browser globals
9-
factory(jQuery || window.django.jQuery)
8+
// Browser globals - prefer Django's jQuery to avoid conflicts
9+
factory(window.django.jQuery || jQuery)
1010
}
1111
}(function ($) {
1212
'use strict'

0 commit comments

Comments
 (0)