Django how to allow multiple selection without ctrl click

182 Views Asked by At

I have a listbox on a Django form

forms.MultipleChoiceField(widget=forms.widgets.SelectMultiple())

How can I enable multiple choice with a simple click to select/unselect , without having to press the ctrl key ?

1

There are 1 best solutions below

5
willeM_ Van Onsem On BEST ANSWER

It might be better to just write this as a list of checkboxes, so with a CheckboxSelectMultiple [Django-doc]:

my_field = forms.MultipleChoiceField(widget=forms.widgets.CheckboxSelectMultiple)

You can wrap it into a scrollable, but by working with checkboxes, it is clear what is selected and what not, and one can easily toggle a single element.