1👍
✅
The problem lied in the inclusion of jQuery on my own with the CDN import in change_form.html
:
<script src="https://code.jquery.com/jquery-3.6.3.slim.min.js" integrity="sha256-ZwqZIVdD3iXNyGHbSYdsmWP//UBokj2FHAxKuSBKDSo=" crossorigin="anonymous"></script>
The Select2 widgets used by Django are initialised using a bundled version of jQuery within Django and the jQuery events fired by those initialised Select2 widgets are processed by that very same jQuery instance.
So the solution is simply to remove the CDN import of jQuery and use the django bundled instance instead. After removing the CDN import, I just added the following declaration at the top of autofocus_select2_searchbars.js
:
const $ = django.jQuery;
the django
variable being available because we extend admin/change_form.html
.
Source:stackexchange.com