Django 1.4 How to customize elements inside MultipleChoiceField

149 views Asked by At

I've set the widget on the MultipleChoiceField with:

self.fields['field_1'] = forms.MultipleChoiceField(
            choices=[(c.name, str(c)) for c in customers],
            widget=forms.CheckboxSelectMultiple()
        )

This ultimately spits out some html where each choice in choices gets an <input> in a <label> in an <li> in a <ul>.

I'd like to set a class on every <li>. I need to remove the bullet point set next to each <li>, change the font size, maybe even style the checkbox. Achievable with CSS selectors, but that strikes me as a code smell.

How can I do that? Thanks!

1

There are 1 answers

0
Vkyishq On

widget=forms.SelectMultiple(attrs={'class': 'yourclassname multi-select'}

I think this will add a class as in

<ul class="yourclassname multi-select">
   <li>...</li>
</ul>

then add css to that class name as, and to remove bullet point you have to just add this

.yourclassname 
{
  list-style: none;
}

Thanks! Hope it helps.