Hello !
I use django-select2 for complex lookup forms and it works very well in all the forms where I add it.
Besides, I am using the attached JS to dynamically add/remove rows in a formset; it works very well for most of my formset use cases.
Unfortunately, when adding/removing a row where one of the fields is a select2, the related select2 js is not populated and I end up with a basic select field. I have a very limited JS knowledge 😅 and I only managed to get this far after scraping various forums - do you see something I need to tweak in the JS in order to call the .select2() at the right moment ? If you have materials where I am able to learn more on this topic I am very interested.
Thanks in advance !
class ContactS2Widget(s2forms.Select2Widget):
search_fields = [
"nomcomplet__icontains",
"mail__icontains",
"mail_perso__icontains",
"adresse__icontains",
"ville__icontains",
"note__icontains",
]
class ActeursForm(forms.ModelForm):
class Meta:
model = Acteurs
exclude = ()
widgets = {
'contact': ContactS2Widget(attrs={"data-theme": "bootstrap4", "class": "form-select"}),
'role': forms.widgets.Select(attrs={"class": "form-select"}),
}