Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#29200 closed Bug (fixed)

RadioSelect does not render its label in MultiWidget

Reported by: Takayuki Hirai Owned by: Tim Graham
Component: Forms Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The code:

from django import forms


class MyWidget(forms.MultiWidget):
    def __init__(self):
        widgets = [
            forms.RadioSelect(
                choices=[('aaa', 'bbb')]
            )
        ]
        super(MyWidget, self).__init__(
            widgets=widgets,
            attrs={},
        )

    def decompress(self, v):
        return []


print(MyWidget().render('wname', None))

Actual output:

<ul>
    <li><input type="radio" name="wname_0" value="aaa" />


</li>
</ul>

Expected output:

<ul>
    <li><label><input type="radio" name="wname_0" value="aaa" />
 bbb</label>

</li>
</ul>

It seems that this problem is caused by the following reasons:

  • a template of RadioSelect requires wrap_label context varialbe to render LABEL elements
  • MultiWidget.get_context() drops wrap_label

Change History (8)

comment:1 Changed 4 years ago by Takayuki Hirai

Type: UncategorizedBug

comment:2 Changed 4 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:3 Changed 4 years ago by Tim Graham

Owner: changed from nobody to Tim Graham
Status: newassigned

comment:4 Changed 4 years ago by Tim Graham

Has patch: set

comment:5 Changed 4 years ago by Carlton Gibson

Triage Stage: AcceptedReady for checkin

comment:6 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 87dc0844:

Fixed #29200 -- Fixed label rendering when using RadioSelect and CheckboxSelectMultiple with MultiWidget.

comment:7 Changed 4 years ago by karyon

there's no backport to 2.0.x, is that intended?

comment:8 Changed 4 years ago by Tim Graham

Yes, it doesn't qualify for a backport based on the supported versions policy

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