horse
horse

Reputation: 501

How to add class to options within a CheckboxSelectMultiple displayed with crispy forms

I'm wanting to add bootstrap classes to the options of a CheckboxSelectMultiple displayed with crispy forms. I know how to add a class to the whole CheckboxSelectMultiple div, but not to each of the elements within it (I'm wanting to give each a class of col-3 so they align next to each other in a neat grid).

I'm displaying the form (the form also has many other fields) with:

{% crispy form form.helper %}

and this is the form.py

TOPICS = (
        ('ANI', 'Animals'),
        ('ART', 'Art'),
        ('COM', 'Communication'),
        ('CRI', 'Crime'),
        ('CUL', 'Culture/Society'),
    )

topics = forms.MultipleChoiceField(choices=TOPICS, required=False, widget=forms.CheckboxSelectMultiple())

Thank you.

Upvotes: 0

Views: 928

Answers (1)

David Smith
David Smith

Reputation: 1306

I think you are looking forinlinecheckboxes. If you want only so many items on each row you can over ride the inlinecheckbox template with col-3 (or col-md-3?).

https://django-crispy-forms.readthedocs.io/en/latest/layouts.html#bootstrap-layout-objects

Upvotes: 0

Related Questions