Opened 3 years ago

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

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 Changed 3 years ago by lraucy

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to lraucy
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 3 years ago by lraucy

  • Has patch set
  • Status changed from assigned to new

comment:3 Changed 3 years ago by ptone

  • Triage Stage changed from Unreviewed to Accepted

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

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

  • Resolution set to fixed
  • Status changed from new to closed

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