Hi,
I would like to use django-select2 to have multiple selection.
But the result in terms of presentation is not at all up to the level even by adding the class: "form-select form-select-sm form-select-solid"
How to solve it ?
Thank fot your help.
Regards
Hi,
Have you checked the official documentation for django-select2? You can find detailed information and examples on how to customize and style the select2 widget on their documentation website
https://django-select2.readthedocs.io/en/latest/
Hi,
Yes,
I try with
{{ form.appellation|add_class:"form-select form-select-solid"|attr:"data-control:select2"}}
with no success
The code snippet you provided seems to have some syntax issues. If you're trying to add classes and attributes to a form element using Twig, you can do it like this:
{{ form_widget(form.appellation, {"attr": {"class": "form-select form-select-solid", "data-control": "select2"}}) }}
form.appellation
represents the form field you want to modify.Hi Faizal,
No it's ok with django-widget-tweaks package.
it's "just" there is something between django-select2 and metronic select2 :/
Regards
Hi Faizal, no news ?
I have form-select form-select-solid in my select but with no sucess..:/
<select name="appellation" lang="fr" data-minimum-input-length="0" data-theme="default" data-allow-clear="false" data-control="select2" class="form-select form-select-solid django-select2 select2-hidden-accessible" required="" multiple="" data-select2- tabindex="-1" aria-hidden="true">
<option value="1">Saint Estèphe</option>
<option value="2">Pauillac</option>
<option value="5">Pessac Léognan</option>
<option value="6">Sauternes</option>
<option value="7">Saint Emilion</option>
<option value="8">Pomerol</option>
<option value="12">Margaux</option>
<option value="13">Saint Julien</option>
</select>
Hi Faizal,
Yes it work like you. But it's not metronic css !
look in dark mode...:/
regards
I recommend using Select2 from the Metronic HTML version. You can refer to the Select2 documentation here:
https://preview.keenthemes.com/html/metronic/docs/forms/select2#multiple-selection
This documentation provides guidance on how to implement and configure Select2 to achieve the desired functionality, which should work similarly to the example provided in the documentation.
<br />
Hi Faizal, il solve it !
So, for everyone :
model.py with a ManyToManyField
class Ranking(models.Model):
name = models.CharField(db_index=True, max_length=200)
initials = models.CharField(db_index=True, max_length=10, blank=True, null=True)
appellation = models.ManyToManyField(Appellation)
class RankingForm(forms.ModelForm):
appellation = forms.ModelMultipleChoiceField(
widget = forms.SelectMultiple,
queryset = Appellation.objects.all()
)
class Meta:
model = Ranking
fields = "__all__"
{% load widget_tweaks %}
{{ form.appellation|add_class:"form-select form-select-solid"|attr:"data-control:select2"}}
I'm glad to hear that you were able to resolve the issue! Your provided solution can be helpful for others. If you have any more questions or need further assistance, please feel free to reach out. Thank you for sharing your experience!