[formfields,formwidgets] move default size and maxlength from field to widget init (that is quite still unsatisfactorily) stable
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Thu, 09 Jul 2009 15:15:18 +0200
branchstable
changeset 2356 ef9e30485ee7
parent 2355 359903ef980a
child 2357 e65e352cfde3
[formfields,formwidgets] move default size and maxlength from field to widget init (that is quite still unsatisfactorily)
web/formfields.py
web/formwidgets.py
--- a/web/formfields.py	Thu Jul 09 14:39:56 2009 +0200
+++ b/web/formfields.py	Thu Jul 09 15:15:18 2009 +0200
@@ -203,8 +203,6 @@
                 widget = Select()
             elif self.max_length and self.max_length < 257:
                 widget = TextInput()
-                widget.attrs.setdefault('size', min(45, self.max_length))
-                widget.attrs.setdefault('maxlength', self.max_length)
 
         super(StringField, self).init_widget(widget)
         if isinstance(self.widget, TextArea):
--- a/web/formwidgets.py	Thu Jul 09 14:39:56 2009 +0200
+++ b/web/formwidgets.py	Thu Jul 09 15:15:18 2009 +0200
@@ -89,6 +89,13 @@
     """<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