Skip to content

Commit 7c001d8

Browse files
mardukbpcodingjoe
andauthored
Update django_select2/static/django_select2/django_select2.js
Co-authored-by: Johannes Maron <[email protected]>
1 parent 3599159 commit 7c001d8

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

django_select2/static/django_select2/django_select2.js

+3-23
Original file line numberDiff line numberDiff line change
@@ -68,31 +68,11 @@
6868
}
6969

7070
$(function () {
71-
$('.django-select2').djangoSelect2()
71+
$('.django-select2').not('[name*=__prefix__]').djangoAdminSelect2()
7272

73-
// This part fixes new inlines not having the correct select2 widgets
74-
function handleFormsetAdded (row, formsetName) {
75-
// Converting to the "normal jQuery"
76-
const jqRow = $(row)
77-
78-
// Because select2 was already instantiated on the empty form, we need to remove it, destroy the instance,
79-
// and re-instantiate it.
80-
jqRow.find('.django-select2').parent().find('.select2-container').remove()
81-
jqRow.find('.django-select2').djangoSelect2('destroy')
82-
jqRow.find('.django-select2').djangoSelect2()
83-
}
84-
85-
// See: https://docs.djangoproject.com/en/dev/ref/contrib/admin/javascript/#supporting-versions-of-django-older-than-4-1
86-
$(document).on('formset:added', function (event, $row, formsetName) {
87-
if (event.detail && event.detail.formsetName) {
88-
// Django >= 4.1
89-
handleFormsetAdded(event.target, event.detail.formsetName)
90-
} else {
91-
// Django < 4.1, use $row and formsetName
92-
handleFormsetAdded($row.get(0), formsetName)
93-
}
73+
document.addEventListener('formset:added', (event) => {
74+
$(event.target).find('.django-select2').djangoSelect2()
9475
})
95-
// End of fix
9676
})
9777

9878
return $.fn.djangoSelect2

0 commit comments

Comments
 (0)