Initial Values ​​for CheckboxSelectMultiple

I initialize the form using:

MultiSubscriptionForm(initial={'email': user.email})

In my form, I would also like to initialize the CheckboxSelectMultiple widget to check the checkbox set. How can i do this?

+3
source share
2 answers

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

MultiSubscriptionForm(initial={
    'email': user.email,
    'multiple_field': ['a', 'b', 'c'],
})
+4
source

I have the same problem. Where I have several flags, I need to choose dynamically (by default the choice of flags) with the initial value. I can manage this by passing a list.

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

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

, mylist . " "

: -)

-Vikram

+3

Source: https://habr.com/ru/post/1775076/


All Articles