djangoformsmulti-selectmultiplechoicefield

Django how to allow multiple selection without ctrl click


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 ?


Solution

  • 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.