Opened 12 years ago

Closed 12 years ago

#19581 closed Bug (fixed)

Duplicate IDs with CheckboxSelectMultiple if ID passed to constructor

Reported by: lraucy Owned by: lraucy
Component: Forms Version: dev
Severity: Normal Keywords: CheckboxSelectMultiple ID
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When a CheckboxSelectMultiple widget is instantiated with attrs passed to the constructor, render() produces invalid HTML:
all the input tags use the same html ID.

Exemple:

from django.forms.widgets import CheckboxSelectMultiple
print CheckboxSelectMultiple(attrs={'id': 'abc'}).render('letters', list('ac'), choices=zip(list('abc'), list('ABC')))

Result:

<ul>
<li><label><input checked="checked" type="checkbox" id="abc" value="a" name="letters" /> A</label></li>
<li><label><input type="checkbox" id="abc" value="b" name="letters" /> B</label></li>
<li><label><input checked="checked" type="checkbox" id="abc" value="c" name="letters" /> C</label></li>
</ul>

Change History (4)

comment:1 by lraucy, 12 years ago

Owner: changed from nobody to lraucy
Status: newassigned

comment:2 by lraucy, 12 years ago

Has patch: set
Status: assignednew

comment:3 by Preston Holmes, 12 years ago

Triage Stage: UnreviewedAccepted

This is prob RFC but on my mobile so can't do a full verification, but looks good.

comment:4 by Preston Holmes <preston@…>, 12 years ago

Resolution: fixed
Status: newclosed

In 62f842e2e568c87387e3da3ab76600bd0aab3e95:

Fixed #19581 -- ensure unique html ids with CheckboxSelectMultiple widgets

ID check is now done the same way as MultipleHiddenInput.

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