changeset 2151:dd3abe290142

Add a makeMultiSelection() function which creates a multiple <select> element.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Mon, 18 Jun 2007 02:12:04 +0200
parents b01a6ef1be4c
children cf4c4a3d6085
files MoinMoin/util/web.py
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/util/web.py	Sun Jun 17 15:25:40 2007 +0200
+++ b/MoinMoin/util/web.py	Mon Jun 18 02:12:04 2007 +0200
@@ -44,6 +44,24 @@
 
     return result
 
+def makeMultiSelection(name, values, selectedvals=None, size=5):
+    """Make a HTML multiple <select> element with named `name` from a value list.
+    
+    The list can either be a list of strings, or a list of (value, label) tuples.
+    `selectedvals` is a list of values that should be pre-selected.
+    
+    """
+    from MoinMoin.widget import html
+    result = html.SELECT(name=name, size="%d" % int(size), multiple=True)
+    for val in values:
+        if not isinstance(val, type(())):
+            val = (val, val)
+        result.append(html.OPTION(
+            value=val[0], selected=(val[0] in selectedvals))
+            .append(html.Text(val[1]))
+        )
+    
+    return result
 
 class Color:
     """ RGB-Triple that automatically converts from and to