Skip to content

Commit 352811b

Browse files
mardukbpcodingjoe
andauthored
Fix #297 -- Add Django admin' inline formset support (#300)
As described in #249 and #297 django-select2 does not currently work with selects added dynamically in the Django admin. The solution was implemented in #249 and all credit should go to Jurrian Tromp. I only added a small correction: ```diff - jqRow.find('.select2-container').remove() + jqRow.find('.django-select2').parent().find('.select2-container').remove() ``` to only remove `.select2-container` when it is a sibling of `.django-select2`. Otherwise the wrong `.select2-container` might get deleted. --------- Co-authored-by: Johannes Maron <[email protected]>
1 parent 12e2d60 commit 352811b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Diff for: django_select2/static/django_select2/django_select2.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@
6868
}
6969

7070
$(function () {
71-
$('.django-select2').djangoSelect2()
71+
$('.django-select2').not('[name*=__prefix__]').djangoSelect2()
72+
73+
document.addEventListener('formset:added', (event) => {
74+
$(event.target).find('.django-select2').djangoSelect2()
75+
})
7276
})
7377

7478
return $.fn.djangoSelect2

0 commit comments

Comments
 (0)