Ticket #2116: CheckboxSelectMultipleField_add_ul_class.patch

File CheckboxSelectMultipleField_add_ul_class.patch, 1.1 KB (added by Jorge Gajon <gajon@…>, 18 years ago)

Adds ul_class parameter to CheckboxSelectMultipleField

  • django/forms/__init__.py

     
    613613    back into the single list that validators, renderers and save() expect.
    614614    """
    615615    requires_data_list = True
    616     def __init__(self, field_name, choices=None, validator_list=None):
     616    def __init__(self, field_name, choices=None, ul_class='', validator_list=None):
    617617        if validator_list is None: validator_list = []
    618618        if choices is None: choices = []
     619        self.ul_class = ul_class
    619620        SelectMultipleField.__init__(self, field_name, choices, size=1, is_required=False, validator_list=validator_list)
    620621
    621622    def prepare(self, new_data):
     
    628629        new_data.setlist(self.field_name, data_list)
    629630
    630631    def render(self, data):
    631         output = ['<ul>']
     632        output = ['<ul%s>' % (self.ul_class and ' class="%s"' % self.ul_class or '')]
    632633        str_data_list = map(str, data) # normalize to strings
    633634        for value, choice in self.choices:
    634635            checked_html = ''
Back to Top