Ticket #11843: 11843.diff

File 11843.diff, 1.2 KB (added by Chris Beaven, 15 years ago)
  • django/forms/widgets.py

     
    247247    def render(self, name, value, attrs=None, choices=()):
    248248        if value is None: value = []
    249249        final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
    250         return mark_safe(u'\n'.join([(u'<input%s />' %
    251             flatatt(dict(value=force_unicode(v), **final_attrs)))
    252             for v in value]))
     250        id_attr = final_attrs.get('id')
     251        inputs = []
     252        for i, v in enumerate(value):
     253            input_attrs = dict(value=force_unicode(v), **final_attrs)
     254            if id_attr:
     255                # An ID attribute was given. Add a numeric index as a suffix
     256                # so that the inputs don't all have the same ID attribute.
     257                input_attrs['id'] = '%s_%s' % (id_attr, i)
     258            inputs.append(u'<input%s />' % flatatt(input_attrs))
     259        return mark_safe(u'\n'.join(inputs))
    253260
    254261    def value_from_datadict(self, data, files, name):
    255262        if isinstance(data, (MultiValueDict, MergeDict)):
Back to Top