Ticket #4117: 4117.diff

File 4117.diff, 1.7 KB (added by Gary Wilson <gary.wilson@…>, 17 years ago)

attributes for containers of RadioSelect and CheckboxSelectMultiple widgets

  • django/newforms/widgets.py

    === modified file 'django/newforms/widgets.py'
     
    253253
    254254    def __unicode__(self):
    255255        "Outputs a <ul> for this set of radio fields."
    256         return u'<ul>\n%s\n</ul>' % u'\n'.join([u'<li>%s</li>' % w for w in self])
     256        contents = u'\n'.join([u'<li>%s</li>' % w for w in self])
     257        return u'<ul%s>\n%s\n</ul>' % (flatatt(self.attrs), contents)
    257258
    258259class RadioSelect(Select):
    259260    def render(self, name, value, attrs=None, choices=()):
     
    278279        if value is None: value = []
    279280        has_id = attrs and 'id' in attrs
    280281        final_attrs = self.build_attrs(attrs, name=name)
    281         output = [u'<ul>']
     282        output = [u'<ul%s>' % flatatt(final_attrs)]
    282283        str_values = set([smart_unicode(v) for v in value]) # Normalize to strings.
    283284        for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
    284285            # If an ID attribute was given, add a numeric index as a suffix,
     
    287288                final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
    288289            cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
    289290            option_value = smart_unicode(option_value)
     291            option_label = escape(smart_unicode(option_label))
    290292            rendered_cb = cb.render(name, option_value)
    291             output.append(u'<li><label>%s %s</label></li>' % (rendered_cb, escape(smart_unicode(option_label))))
     293            contents = u'<label>%s %s</label>' % (rendered_cb, option_label)
     294            output.append(u'<li%s>%s</li>' % (flatatt(final_attrs), contents))
    292295        output.append(u'</ul>')
    293296        return u'\n'.join(output)
    294297
Back to Top