select needs to accept an id tls-sprint
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Fri, 20 Feb 2009 17:38:38 +0100
branchtls-sprint
changeset 909 4685a8c21d73
parent 907 192800415f59
child 910 a86ab461b8fd
select needs to accept an id
common/tags.py
--- a/common/tags.py	Fri Feb 20 17:20:53 2009 +0100
+++ b/common/tags.py	Fri Feb 20 17:38:38 2009 +0100
@@ -15,11 +15,14 @@
 label = tag('label')
 option = tag('option')
 
-def select(name, multiple=False, options=[]):
+def select(name, id=None, multiple=False, options=[]):
+    attrs = {}
     if multiple:
-        html = [u'<select name="%s" multiple="multiple">' % name]
-    else:
-        html = [u'<select name="%s">' % name]
+        attrs['multiple'] = 'multiple'
+    if id:
+        attrs['id'] = id
+    html = [u'<select name="%s" %s>' % (name,
+                                        ' '.join('%s="%s"' % kv for kv in attrs.items()))]
     html += options
     html.append(u'</select>')
     return u'\n'.join(html)