Initial values for CheckboxSelectMultiple
I'm initializing a form using:
MultiSubscriptionForm(initial={'email': user.email})
In my form I'd also like to initialize a Che开发者_JAVA百科ckboxSelectMultiple widget to check a set of checkboxes. How can I do that?
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'],
})
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
精彩评论