checkbox widget should use vocabulary tls-sprint
authorsylvain.thenault@logilab.fr
Wed, 11 Mar 2009 19:51:08 +0100
branchtls-sprint
changeset 1067 f37ee6855e42
parent 1066 3cebd690a114
child 1068 04c745ce692e
checkbox widget should use vocabulary
web/form.py
--- a/web/form.py	Wed Mar 11 19:50:33 2009 +0100
+++ b/web/form.py	Wed Mar 11 19:51:08 2009 +0100
@@ -381,11 +381,18 @@
 class CheckBox(Input):
     type = 'checkbox'
     
-    def _render_attrs(self, form, field):
-        name, values, attrs = super(CheckBox, self)._render_attrs(form, field)
-        if values and values[0]:
-            attrs['checked'] = u'checked'
-        return name, values, attrs
+    def render(self, form, field):
+        name, curvalues, attrs = self._render_attrs(form, field)
+        options = []
+        for label, value in field.vocabulary(form):
+            if value in curvalues:
+                tag = tags.input(name=name, value=value, type=self.type,
+                                 checked='checked', **attrs)
+            else:
+                tag = tags.input(name=name, value=value, type=self.type,
+                                 **attrs)
+            options.append(tag + label)
+        return '<br/>\n'.join(options)
 
         
 class Radio(Input):