Nico44044
Nico44044

Reputation: 411

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 ?

Upvotes: 1

Views: 379

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476557

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.

Upvotes: 2

Related Questions