fix <optgroup> tag cannot be empty according to DTD tls-sprint
authorFlorent <florent@secondweb.fr>
Wed, 13 May 2009 08:58:32 +0200
branchtls-sprint
changeset 1771 bb9538d91465
parent 1768 b59b7c422a8a
child 1772 21d1db460cdb
fix <optgroup> tag cannot be empty according to DTD
web/formwidgets.py
--- a/web/formwidgets.py	Wed May 13 08:41:23 2009 +0200
+++ b/web/formwidgets.py	Wed May 13 08:58:32 2009 +0200
@@ -173,14 +173,20 @@
         if not 'size' in attrs and self._multiple:
             attrs['size'] = '5'
         options = []
+        optgroup_opened = False
         for label, value in field.vocabulary(form):
             if value is None:
                 # handle separator
-                options.append(u'<optgroup label="%s"/>' % (label or ''))
+                if optgroup_opened:
+                    options.append(u'</optgroup>')
+                options.append(u'<optgroup label="%s">' % (label or ''))
+                optgroup_opened = True
             elif value in curvalues:
                 options.append(tags.option(label, value=value, selected='selected'))
             else:
                 options.append(tags.option(label, value=value))
+        if optgroup_opened:
+            options.append(u'</optgroup>')
         return tags.select(name=name, multiple=self._multiple,
                            options=options, **attrs)