vendredi 25 mai 2018

adding css to django checkbox multiselect

I managed to add css classes to my forms with

attrs={'class': 'form-control'}

For example in a Multiple Choice Field:

    CHOICES_NAT = (('None', 'None'),('Deutschland', 'Deutschland'), ('Amerika', 'Amerika'), ('Türkei','Türkei'), ('Frankreich', 'Frankreich'))
    Nationality = forms.ChoiceField(widget = forms.Select(attrs={'class': 'form-control'}), choices = CHOICES_NAT)

But i still fail to display the checkboxes of a Multiple Choice Field. The Choices are displayed only the Chechboxes are missing. Heres my code for the Ceckboxes:

    CHOICES_AGE = (('0-8', '0-8'),('8-14', '8-14'), ('14-21', '14-21'), ('21-60','21-60'), ('60-90', '60-90'))
    Target_Age = forms.MultipleChoiceField(widget = forms.CheckboxSelectMultiple(attrs={'class':'form-group', 'type':'checkbox',}), choices = CHOICES_AGE, )

As far as i can see the type is not added to the html - i might need to pass multiple attrs differently.

Thanks for your help! =)




Aucun commentaire:

Enregistrer un commentaire