Skip to content

🐛 When I use django-select2 with HTMX, the new forms sometimes have major display issues. #319

Answered by madtools
LBWright asked this question in Q&A

You must be logged in to vote

Hi,

In your base template, put something like this so that when htmx is done loading new content, it will initialize django-select2 widget correctly.

htmx.onLoad(function() {
    $('.django-select2').djangoSelect2();
});

Also, if you widget is in a modal, this line may help you (my modal has an id "modal"):

$('.django-select2').djangoSelect2({dropdownParent: $('#modal')});

Replies: 1 comment

You must be logged in to vote
0 replies
Answer selected by codingjoe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #317 on March 15, 2025 14:18.