Opened 3 months ago

Closed 3 months ago

#35409 closed Bug (worksforme)

CheckbioxMultipleSelect widget is broken

Reported by: Marc Gomillion Owned by: nobody
Component: Forms Version: 4.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Natalia Bidart)

My application has an emailer page with a list of recipients that can be edited as follows.

In the form definition:

recipients = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple)

In __init__:

self.fields['recipients'].choices = recipient_choices 

This has worked since 2009, but Django 4.2.x has broken it as it does not insert line breaks between the recipients and the list is a jumbled mess. I've coded around it by using the SelectMultiple widget, which still allows editing of the list, but not in obvious ways to my users, and is thus unacceptable.

I've attached images of the list using Django 3.2 and 4.2.

Attachments (2)

recipient list 3.2.png (20.1 KB ) - added by Marc Gomillion 3 months ago.
recipient list 4.2.png (17.5 KB ) - added by Marc Gomillion 3 months ago.

Download all attachments as: .zip

Change History (3)

by Marc Gomillion, 3 months ago

Attachment: recipient list 3.2.png added

by Marc Gomillion, 3 months ago

Attachment: recipient list 4.2.png added

comment:1 by Natalia Bidart, 3 months ago

Component: UncategorizedForms
Description: modified (diff)
Resolution: worksforme
Status: newclosed
Type: UncategorizedBug

Hello Marc! Thank you for your report. In order to do a proper triage of this ticket, I need your help with the following:

  1. Could you please confirm that this issue is present in the main branch of the Django project?
  2. Could you please provide a minimal reproducer with the form you used and template?

A few things to note:

  • Django 3.2 is no longer supported and Django 4.2 is on security-fixes-only support mode.
  • Django 4.1 introduced some transitional form renderer classes to ease migration to 5.0 where there is a change in how the forms are rendered by default (using <div>), please check the release notes for 4.1 and 5.0.

I tried to reproduce this with no success. My form is as follows:

from django import forms

class MyForm(forms.Form):
    recipients = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple)

    def __init__(self, *a, **kw):
        super().__init__(*a, **kw)
        recipient_choices = [(i, f"User {i} with email {i}@something") for i in range(5)]
        self.fields['recipients'].choices = recipient_choices

And when rendering it with {{ form }} in a Django template, I get a nice looking form:


Closing as worksforme until a minimal reproducer or more information is provided.

Note: See TracTickets for help on using tickets.
Back to Top