if choices is set and widget not explicitly specified, use Select in base field
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 28 May 2009 18:45:51 +0200
changeset 1988 b5c5c088bb03
parent 1987 d495e9ce9367
child 1989 8c8dead642f7
if choices is set and widget not explicitly specified, use Select in base field
web/formfields.py
--- a/web/formfields.py	Thu May 28 18:32:51 2009 +0200
+++ b/web/formfields.py	Thu May 28 18:45:51 2009 +0200
@@ -101,6 +101,8 @@
         return self.__unicode__().encode('utf-8')
 
     def init_widget(self, widget):
+        if widget is None and self.choices:
+            widget = Select()
         if widget is not None:
             self.widget = widget
         if isinstance(self.widget, type):
@@ -192,9 +194,9 @@
     def init_widget(self, widget):
         if widget is None:
             if self.choices:
-                self.widget = Select()
+                widget = Select()
             elif self.max_length and self.max_length < 257:
-                self.widget = TextInput()
+                widget = TextInput()
         super(StringField, self).init_widget(widget)
         if isinstance(self.widget, TextArea):
             self.init_text_area(self.widget)