2

For a given field, is it possible to have all boxes initially checked, but one?

Currently I am using: widget=forms.CheckboxSelectMultiple({'checked':'checked'}) to have all checkboxes initially checked. Is there a way to set this for each checkbox individually?

bsuire
  • 1,383
  • 2
  • 18
  • 27
  • There is an "initial" parameter. have a look here: https://docs.djangoproject.com/en/dev/ref/forms/api/#dynamic-initial-values – Jingo Aug 16 '13 at 16:09
  • Thanks. I've looked this up but I haven't been able to use dynamic initial values. I have tried on charfield that are also present in my forms and should be simpler to deal with but it doesn't display the given values in the box. Do you have some experience using dynamic init? – bsuire Aug 19 '13 at 13:23
  • I suppose another way around would be to modify the auto-generated html and simply insert checked= 'checked' wherever I want to, but that seems to go against Django's design and good practice. – bsuire Aug 19 '13 at 13:24
  • I have the same problem. There is a question related to it: https://stackoverflow.com/questions/4189970/initial-values-for-checkboxselectmultiple, but it doesn't work for me... – Leo Skhrnkv Jun 28 '17 at 16:14

0 Answers0