radio widget tls-sprint
authorsylvain.thenault@logilab.fr
Wed, 11 Mar 2009 11:51:52 +0100
branchtls-sprint
changeset 1056 be43d95ebb52
parent 1055 b87222b63950
child 1057 6636c75c4aa9
radio widget
web/form.py
--- a/web/form.py	Wed Mar 11 11:34:46 2009 +0100
+++ b/web/form.py	Wed Mar 11 11:51:52 2009 +0100
@@ -369,9 +369,8 @@
         
     def render(self, form, field):
         name, curvalues, attrs = self._render_attrs(form, field)
-        vocab = field.vocabulary(form)
         options = []
-        for label, value in vocab:
+        for label, value in field.vocabulary(form):
             if value in curvalues:
                 options.append(tags.option(label, value=value, selected='selected'))
             else:
@@ -392,8 +391,20 @@
         return name, values, attrs
 
         
-class Radio(FieldWidget):
-    pass
+class Radio(Input):
+    type = 'radio'
+    setdomid = False
+    
+    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:
+                options.append(tags.input(name=name, type=self.type, value=value, checked='checked', **attrs))
+            else:
+                options.append(tags.option(name=name, type=self.type, value=value, **attrs))
+            options[-1] += label + '<br/>'
+        return '\n'.join(options)
 
 
 class DateTimePicker(TextInput):