[formwidgets,formfields] hum, this way stable
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Thu, 09 Jul 2009 16:44:34 +0200
branchstable
changeset 2360 1d43aa551ba9
parent 2359 d78cf4586707
child 2361 8f00836580f1
[formwidgets,formfields] hum, this way
web/formfields.py
web/formwidgets.py
--- a/web/formfields.py	Thu Jul 09 16:15:52 2009 +0200
+++ b/web/formfields.py	Thu Jul 09 16:44:34 2009 +0200
@@ -207,6 +207,13 @@
         super(StringField, self).init_widget(widget)
         if isinstance(self.widget, TextArea):
             self.init_text_area(self.widget)
+        if isinstance(self.widget, TextInput):
+            self.init_text_input(self.widget)
+
+    def init_text_input(self, widget):
+        if self.max_length:
+            widget.attrs.setdefault('size', min(45, self.max_length))
+            widget.attrs.setdefault('maxlength', self.max_length)
 
     def init_text_area(self, widget):
         if self.max_length < 513:
--- a/web/formwidgets.py	Thu Jul 09 16:15:52 2009 +0200
+++ b/web/formwidgets.py	Thu Jul 09 16:44:34 2009 +0200
@@ -89,13 +89,6 @@
     """<input type='text'>"""
     type = 'text'
 
-    def render(self, form, field):
-        if hasattr(field, 'max_length') and field.max_length:
-            self.attrs.setdefault('size', min(45, field.max_length))
-            self.attrs.setdefault('maxlength', field.max_length)
-        return super(TextInput, self).render(form, field)
-
-
 
 class PasswordInput(Input):
     """<input type='password'> and its confirmation field (using