Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django form multiple select box size in template

I have a template:

    ...
    <form action="/reportform/" method="post">
    <p><label>Aircraft system:</label>
    <br>{{ Querry.system }}
    ...

it looks like this

How can I set a Size option for this box? for example, 10.

like image 637
maksymov Avatar asked Oct 01 '11 15:10

maksymov


1 Answers

Use the attrs attribute to define the size.

class MyForm(forms.Form):
    system = forms.ChoiceField(choices=SYSTEM_CHOICES,
        widget=forms.SelectMultiple(attrs={'size':'40'}))

Sometimes, it is useful to override the widget in the forms init method.

class MyForm(forms.Form):
    <snip>
    def __init__(self, *args, **kwargs):
        super(MyForm, self).__init__(*args, **kwargs)
        self.fields['system'].widget = forms.SelectMultiple(attrs={'size':'40'}))
like image 107
Alasdair Avatar answered Oct 21 '22 17:10

Alasdair