[Django]-Initial values for CheckboxSelectMultiple

5👍

More or less the same actually, just pass a list of values and it works.

MultiSubscriptionForm(initial={
    'email': user.email,
    'multiple_field': ['a', 'b', 'c'],
})
👤Wolph

3👍

I got the same problem, Where I am the multiple checkboxes need to select dynamically (default selection of checkboxes) with initial value. I can able to manage the by passing the list.

mylist=['None','Fixed','Error']

error= forms.MultipleChoiceField(choices = formfields.ErrorType,widget = CheckboxSelectMultiple(),initial = mylist)

If I write the above code in my form class the values in mylist were selected by default when the form loads. your answer “Passing the values as list” solved my actual problem

Thanks for the clue 🙂

-Vikram

👤vkrams

Leave a comment