Opened 7 years ago

Closed 7 years ago

#19581 closed Bug (fixed)

Duplicate IDs with CheckboxSelectMultiple if ID passed to constructor

Reported by: lraucy Owned by: lraucy
Component: Forms Version: master
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


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.


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


<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>

Change History (4)

comment:1 Changed 7 years ago by lraucy

Owner: changed from nobody to lraucy
Status: newassigned

comment:2 Changed 7 years ago by lraucy

Has patch: set
Status: assignednew

comment:3 Changed 7 years ago by Preston Holmes

Triage Stage: UnreviewedAccepted

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

comment:4 Changed 7 years ago by Preston Holmes <preston@…>

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