5

Following the code in this post, I was able to group the options in a ModelMultipleChoiceField based on another field. As described in this post, I used a custom widget (literally the one that is in the post):

Grouping CheckboxSelectMultiple Options in Django

so now the form is rendering the way I'd like it to, but I was hoping to improve on the formatting by using crispy forms. however, when I added {% load crispy_forms_tags %} and {{form|crispy}} it rendered the form without the grouping that I worked so hard to achieve...

does anyone know how if its possible to apply crispy forms to a form with a custom widget and preserve what the widget does?

thanks!

Community
  • 1
  • 1
Yin Li
  • 119
  • 1
  • 9

1 Answers1

7

No, this won't be possible because crispy forms never calls the render method of the widget.

An alternative is to override the template for the widget, in this case bootstrap/layout/checkboxselectmultiple.html, to use the grouping as required.

https://github.com/maraujop/django-crispy-forms/blob/dev/crispy_forms/templates/bootstrap/layout/checkboxselectmultiple.html

tuxcanfly
  • 2,494
  • 1
  • 20
  • 18