Forms ModelMultipleChoiceField with checkboxes?

562 views
Skip to first unread message

Benjamin Wolf

unread,
Nov 19, 2009, 4:19:14 AM11/19/09
to django...@googlegroups.com
Hello,

I'm using Django's form and ModelMultipleChoiceField.
ModelMultipleChoiceField produces a select list with multiple options.
Is it possible to use
checkboxes instead?

Thanks,
Greets Ben

aa56280

unread,
Nov 21, 2009, 4:09:48 PM11/21/09
to Django users
Yes, have a look at this: http://docs.djangoproject.com/en/dev/ref/forms/widgets/#specifying-widgets

The widget class for Checkboxes would be django.forms.widgets import
CheckboxSelectMultiple

Hope that helps.

leoz01

unread,
Nov 20, 2009, 4:52:20 AM11/20/09
to Django users
I think the easiest way is to make your own widget or otherwise you
can make your own form field.
Message has been deleted

aa56280

unread,
Nov 23, 2009, 3:14:48 PM11/23/09
to Django users
leoz01, Django comes with a widget for precisely this use case (check
link above). Creating your own would be a complete waste of time.

Tim Valenta

unread,
Nov 23, 2009, 6:20:35 PM11/23/09
to Django users
That widget doesn't seem to look right on *any* browser. It's got
this weird step-like appearance. Firefox is the only browser where it
appears even close to acceptable. I might be submitting a patch for
the CSS soon... It's horrible.

Tim Valenta

unread,
Nov 23, 2009, 6:24:27 PM11/23/09
to Django users
Actually-- quick followup:

The widget looks alright if you haven't got the 'aligned' css class on
the fieldset. But if you do, watch out :P

Benjamin Wolf

unread,
Nov 23, 2009, 7:27:21 PM11/23/09
to django...@googlegroups.com
Hi there,

very nice, the CheckboxSelectMultiple is what I want.
But one thing:
The default rendering of the checkboxes is
<li>
<label for="id"><input type="checkbox" id="id" name="id"/>
Lagerbevorratung</label>
</li>

it would be great if I could display the input-element outside of the
label-tag.
Perhaps it is possible to iterate over the options of the
CheckboxSelectMultiple-Field in the template?

Thanks again,
greets b

Tim Valenta schrieb:
> --
>
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=.
>
>
>

Reply all
Reply to author
Forward
0 new messages