diff options
| author | Loic Raucy <lraucy@multiposting.fr> | 2013-01-09 10:07:44 +0100 |
|---|---|---|
| committer | Preston Holmes <preston@ptone.com> | 2013-01-09 16:06:56 -0800 |
| commit | 62f842e2e568c87387e3da3ab76600bd0aab3e95 (patch) | |
| tree | 38f2898366966d69d74b0106a07c4cbcffb5f6ab /django/forms/widgets.py | |
| parent | 227bd3f8dbcedb4d90cf5474bc237ca4bd46d49d (diff) | |
Fixed #19581 -- ensure unique html ids with CheckboxSelectMultiple widgets
ID check is now done the same way as MultipleHiddenInput.
Diffstat (limited to 'django/forms/widgets.py')
| -rw-r--r-- | django/forms/widgets.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 4782b99117..d6ea56f0c8 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -754,17 +754,17 @@ class RadioSelect(Select): class CheckboxSelectMultiple(SelectMultiple): def render(self, name, value, attrs=None, choices=()): if value is None: value = [] - has_id = attrs and 'id' in attrs final_attrs = self.build_attrs(attrs, name=name) + id_ = final_attrs.get('id', None) output = ['<ul>'] # Normalize to strings str_values = set([force_text(v) for v in value]) for i, (option_value, option_label) in enumerate(chain(self.choices, choices)): # If an ID attribute was given, add a numeric index as a suffix, # so that the checkboxes don't all have the same ID attribute. - if has_id: - final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i)) - label_for = format_html(' for="{0}"', final_attrs['id']) + if id_: + final_attrs = dict(final_attrs, id='%s_%s' % (id_, i)) + label_for = format_html(' for="{0}_{1}"', id_, i) else: label_for = '' |
