user391986
user391986

Reputation: 30946

django form add css to ModelMultipleChoiceFIeld

How exactly do I add css to a forms.ModelMultipleChoiceField I tried to pass in attrs={'class' : 'foo'} But it's failing saying "__init__() got an unexpected keyword argument 'attrs'"

my_list = forms.ModelMultipleChoiceField(label='List', required=False, queryset=[])

Upvotes: 1

Views: 2023

Answers (1)

It's the widget that needs the attrs, not the form field.

my_list = forms.ModelMultipleChoiceField(
    label='List',
    required=False,
    queryset=[],
    widget=SelectMultiple(attrs={'class': 'foobar'}))

Upvotes: 5

Related Questions